• 大小: 13.92MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-07-31
  • 语言: Python
  • 标签: 文本分类  

资源简介

Python,TensorFlow实现文本分类代码集合(含数据)_TextCNN_TextRNN_TextRCNN_HierarchicalAttentionNetwork__Seq2seqWithAttention等等9种文本分类算法实现代码

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
#prediction using multi-models. take out: create multiple graphs. each graph associate with a session. add logits of models.
#process--->1.load data(X:list of linty:int). 2.create session. 3.feed data. 4.predict
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
import tensorflow as tf
import numpy as np
import os
from a3_entity_network import EntityNetwork
sys.path.append(“..“)
from a08_DynamicMemoryNetwork.data_util_zhihu import load_data_predictload_final_test_datacreate_voabularycreate_voabulary_label
from tflearn.data_utils import pad_sequences #to_categorical
import codecs
from a08_DynamicMemoryNetwork.a8_dynamic_memory_network import DynamicMemoryNetwork
from p7_TextCNN_model import TextCNN
from p71_TextRCNN_mode2 import TextRCNN

#configuration
FLAGS=tf.app.flags.FLAGS
tf.app.flags.DEFINE_integer(“num_classes“1999“number of label“)
tf.app.flags.DEFINE_float(“learning_rate“0.01“learning rate“)
tf.app.flags.DEFINE_integer(“batch_size“ 80 “Batch size for training/evaluating.“) #批处理的大小 32-->128
tf.app.flags.DEFINE_integer(“decay_steps“ 6000 “how many steps before decay learning rate.“) #6000批处理的大小 32-->128
tf.app.flags.DEFINE_float(“decay_rate“ 1.0 “Rate of decay for learning rate.“) #0.65一次衰减多少
tf.app.flags.DEFINE_string(“ckpt_dir_dmn““../checkpoint_dynamic_memory_network/““checkpoint location for the model“)
tf.app.flags.DEFINE_integer(“sequence_length“60“max sentence length“)
tf.app.flags.DEFINE_integer(“embed_size“100“embedding size“)
tf.app.flags.DEFINE_boolean(“is_training“False“is traning.true:traniningfalse:testing/inference“)
tf.app.flags.DEFINE_integer(“num_epochs“1“number of epochs to run.“)
tf.app.flags.DEFINE_integer(“validate_every“ 1 “Validate every validate_every epochs.“) #每10轮做一次验证
tf.app.flags.DEFINE_boolean(“use_embedding“True“whether to use embedding or not.“)
#tf.app.flags.DEFINE_string(“cache_path““text_cnn_checkpoint/data_cache.pik““checkpoint location for the model“)
tf.app.flags.DEFINE_string(“traning_data_path““../train-zhihu4-only-title-all.txt““path of traning data.“) #O.K.train-zhihu4-only-title-all.txt-->training-data/test-zhihu4-only-title.txt--->‘training-data/train-zhihu5-only-title-multilabel.txt‘
tf.app.flags.DEFINE_string(“word2vec_model_path““../zhihu-word2vec-title-desc.bin-100““word2vec‘s vocabulary and vectors“) #zhihu-word2vec.bin-100-->zhihu-word2vec-multilabel-minicount15.bin-100
tf.app.flags.DEFINE_boolean(“multi_label_flag“True“use multi label or single label.“)
tf.app.flags.DEFINE_integer(“hidden_size“100“hidden size“)
tf.app.flags.DEFINE_string(“predict_target_file““zhihu_result_ensemble_2_0814.csv““target file path for final prediction“)
tf.app.flags.DEFINE_string(“predict_source_file“‘../test-zhihu-forpredict-title-desc-v6.txt‘“target file path for final prediction“) #test-zhihu-forpredict-v4only-title.txt
tf.app.flags.DEFINE_integer(“story_length“1“story length“)
tf.app.flags.DEFINE

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         602  2018-05-02 01:24  text_classification-master\.travis.yml
     目录           0  2018-05-02 01:24  text_classification-master\a00_boosting\
     文件        2529  2018-05-02 01:24  text_classification-master\a00_boosting\a08_boosting.py
     目录           0  2018-05-02 01:24  text_classification-master\a01_FastText\
     文件        7221  2018-05-02 01:24  text_classification-master\a01_FastText\p5_fastTextB_model.py
     文件        5292  2018-05-02 01:24  text_classification-master\a01_FastText\p5_fastTextB_predict.py
     文件        5205  2018-05-02 01:24  text_classification-master\a01_FastText\p5_fastTextB_predict_multilabel.py
     文件        9532  2018-05-02 01:24  text_classification-master\a01_FastText\p5_fastTextB_train.py
     文件        6355  2018-05-02 01:24  text_classification-master\a01_FastText\p6_fastTextB_model_multilabel.py
     文件       10138  2018-05-02 01:24  text_classification-master\a01_FastText\p6_fastTextB_train_multilabel.py
     目录           0  2018-05-02 01:24  text_classification-master\a02_TextCNN\
     文件           0  2018-05-02 01:24  text_classification-master\a02_TextCNN\__init__.py
     目录           0  2018-05-02 01:24  text_classification-master\a02_TextCNN\__pycache__\
     文件        3437  2018-05-02 01:24  text_classification-master\a02_TextCNN\__pycache__\data_util.cpython-36.pyc
     文件        4978  2018-05-02 01:24  text_classification-master\a02_TextCNN\__pycache__\p7_TextCNN_model.cpython-36.pyc
     文件        4904  2018-05-02 01:24  text_classification-master\a02_TextCNN\data_util.py
     目录           0  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\
     文件           0  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\__init__.py
     文件       26891  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\data_util_zhihu.py
     文件         693  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_predict_ensemble.py
     文件        9195  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_predict_exp.py
     文件        6698  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_predict_exp512.py
     文件        6670  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_predict_exp512_0609.py
     文件        6727  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_predict_exp512_simple.py
     文件       12163  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_train_exp.py
     文件       14389  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_train_exp_512_0609.py
     文件       12312  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p7_TextCNN_train_exp512.py
     文件        9003  2018-05-02 01:24  text_classification-master\a02_TextCNN\other_experiement\p8_TextCNN_predict_exp.py
     文件       14654  2018-05-02 01:24  text_classification-master\a02_TextCNN\p7_TextCNN_model.py
     文件       14173  2018-05-02 01:24  text_classification-master\a02_TextCNN\p7_TextCNN_model_multilayers.py
     文件        9056  2018-05-02 01:24  text_classification-master\a02_TextCNN\p7_TextCNN_predict.py
............此处省略96个文件信息

评论

共有 条评论