GithubHelp home page GithubHelp logo

norybaby / sentiment_analysis_textcnn Goto Github PK

View Code? Open in Web Editor NEW
340.0 9.0 132.0 4.79 MB

基于tensorflow 实现的用textcnn方法做情感分析的项目,有数据,可以直接跑。

Python 100.00%

sentiment_analysis_textcnn's Introduction

sentiment_analysis_textcnn

基于tensorflow 实现的用textcnn方法做情感分析的项目,有数据,可以直接跑。



环境要求:

python:3.x
tensorflow 1.x



运行

运行训练:python train.py
运行验证:python eval.py
 

image



  如有问题欢迎讨论 [email protected]

sentiment_analysis_textcnn's People

Contributors

norybaby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sentiment_analysis_textcnn's Issues

数据源

想问下这个数据是从哪里来的哈

how to train or eval?

`u@u-VirtualBox:~/sentiment_analysis_textcnn/textcnn$ python train.py

Parameters:
ALLOW_SOFT_PLACEMENT=True
BATCH_SIZE=64
CHECKPOINT_EVERY=100
DEV_SAMPLE_PERCENTAGE=0.1
DROPOUT_KEEP_PROB=0.5
EMBEDDING_DIM=128
EVALUATE_EVERY=50
FILTER_SIZES=2,3,4
L2_REG_LAMBDA=0.0
LOG_DEVICE_PLACEMENT=False
NUM_CHECKPOINTS=5
NUM_EPOCHS=10
NUM_FILTERS=128
TRAIN_DATA_FILE=../data/cutclean_label_corpus10000.txt
TRAIN_LABEL_DATA_FILE=
W2V_FILE=../data/vectors.bin

Loading data...
Traceback (most recent call last):
File "train.py", line 226, in
train(w2v_wr.model)
File "train.py", line 93, in train
x_train, x_dev, y_train, y_dev ,vocab_size= load_data(w2v_model)
File "train.py", line 54, in load_data
x_text, y = data_helpers.load_data_and_labels(FLAGS.train_data_file)
File "/home/u/sentiment_analysis_textcnn/textcnn/data_input_helper.py", line 76, in load_data_and_labels
with open(filepath, 'r', encoding='utf-8',errors='ignore') as f:
TypeError: file() takes at most 3 arguments (4 given)`` eval
u@u-VirtualBox:~/sentiment_analysis_textcnn/textcnn$ python eval.py

Parameters:
ALLOW_SOFT_PLACEMENT=True
BATCH_SIZE=64
CHECKPOINT_DIR=./runs/1501842714/checkpoints/
EVAL_TRAIN=True
LOG_DEVICE_PLACEMENT=False
VALID_DATA_FILE=../data/cutclean_label_corpus10000.txt
W2V_FILE=../data/vectors.bin

2018-01-11 10:02:53.954545: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-11 10:02:53.954615: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-01-11 10:02:53.954634: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Traceback (most recent call last):
File "eval.py", line 107, in
eval(w2v_wr.model)
File "eval.py", line 68, in eval
saver = tf.train.import_meta_graph("{}.meta".format(checkpoint_file))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1679, in import_meta_graph
meta_graph_def = meta_graph.read_meta_graph_file(meta_graph_or_file)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/meta_graph.py", line 402, in read_meta_graph_file
raise IOError("File %s does not exist." % filename)
IOError: File None.meta does not exist.

`

how to deal new data

这个代码的data文件夹中,这里的txt文件和bin文件似乎是一一对应的,那么我想用新数据写好txt文件,怎么得到这里匹配的bin文件???求救

eval报错求助

运行后eval会报错,求问应该如何解决,感谢!
image

runfile('D:/sentiment_analysis_textcnn-master/textcnn/eval.py', wdir='D:/sentiment_analysis_textcnn-master/textcnn')
Reloaded modules: data_input_helper, text_cnn
Traceback (most recent call last):

File "D:\sentiment_analysis_textcnn-master\textcnn\eval.py", line 27, in
tf.flags.DEFINE_string("w2v_file", "../data/vectors.bin", "w2v_file path")

File "D:\caifeng\anaconda\envs\NewEnv\lib\site-packages\tensorflow\python\platform\flags.py", line 58, in wrapper
return original_function(*args, **kwargs)

File "D:\caifeng\anaconda\envs\NewEnv\lib\site-packages\absl\flags_defines.py", line 290, in DEFINE_string
**args)

File "D:\caifeng\anaconda\envs\NewEnv\lib\site-packages\absl\flags_defines.py", line 102, in DEFINE
module_name, required)

File "D:\caifeng\anaconda\envs\NewEnv\lib\site-packages\absl\flags_defines.py", line 136, in DEFINE_flag
fv[flag.name] = flag

File "D:\caifeng\anaconda\envs\NewEnv\lib\site-packages\absl\flags_flagvalues.py", line 429, in setitem
raise _exceptions.DuplicateFlagError.from_flag(name, self)

DuplicateFlagError: The flag 'w2v_file' is defined twice. First from D:\sentiment_analysis_textcnn-master\textcnn\train.py, Second from D:\sentiment_analysis_textcnn-master\textcnn\eval.py. Description from first occurrence: w2v_file path

text_cnn 第80行bug

l2_loss += tf.nn.l2_loss(b)
这里应该是
l2_loss += tf.nn.l2_loss(W)
l2损失正则应该是对W起作用,当然也可以同时加上loss(b),像原始版本的代码一样。

数据

请问您这里用到的数据是谭松波酒店数据集吗?

执行eval.py错误

我训练好权重之后,执行python eval.py,发现并不能够成功预测。因为会显示如下错误:
ValueError: Cannot feed value of shape (64, 1290) for Tensor 'input_x:0', which has shape '(?, 82)'

具体如图所示:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.