practicingman / chinese_text_cnn Goto Github PK
View Code? Open in Web Editor NEWTextCNN Pytorch实现 中文文本分类 情感分析
TextCNN Pytorch实现 中文文本分类 情感分析
Hi, could you tell me where is the dataset comes from?
在高版本的Pytorch(我的1.5.0)中train.py
中的feature.data.t_(), target.data.sub_(1)
会报错,改成以下就没有问题了:
feature = feature.data.t()
target = target.data.sub(1)
您好!
关于您在执行multichannel模式时,命令行选项是
python main.py -static=true -non-static=true -multichannel=true
对应代码是
if args.static:
self.embedding = self.embedding.from_pretrained(args.vectors, freeze=not args.non_static)
if args.multichannel:
self.embedding2 = nn.Embedding(vocabulary_size, embedding_dimension).from_pretrained(args.vectors)
当三个选项均为True时,freeze=not True即freeze=False, 即embedding是微调了的。同时embedding2也是微调的。那这样不就是两个都微调了吗???
是不是应该设置 -non-static=False?
Loading data...
The device
argument should be set by using torch.device
or passing a string
as an argument. This behavior will be deprecated soon and currently defaults to
cpu.
The device
argument should be set by using torch.device
or passing a string
as an argument. This behavior will be deprecated soon and currently defaults to
cpu.
Parameters:
BATCH_SIZE=128
CLASS_NUM=3
CUDA=False
DEVICE=-1
DROPOUT=0.5
EARLY_STOPPING=1000
EMBEDDING_DIM=128
EPOCHS=256
FILTER_NUM=100
FILTER_SIZES=[3, 4, 5]
LOG_INTERVAL=1
LR=0.001
MAX_NORM=3.0
MULTICHANNEL=False
NON_STATIC=False
PRETRAINED_NAME=sgns.zhihu.word
PRETRAINED_PATH=pretrained
SAVE_BEST=True
SAVE_DIR=snapshot
SNAPSHOT=None
STATIC=False
TEST_INTERVAL=100
VOCABULARY_SIZE=35572
Traceback (most recent call last):
File "main.py", line 98, in
train.train(train_iter, dev_iter, text_cnn, args)
File "d:\我的文档\桌面\workspace2\chinese_text_cnn\train.py", line 18, in trai
n
feature.data.t_(), target.data.sub_(1)
RuntimeError: set_storage_offset is not allowed on a Tensor created from .data o
r .detach().
If your intent is to change the metadata of a Tensor (such as sizes / strides /
storage / storage_offset)
without autograd tracking the change, remove the .data / .detach() call and wrap
the change in a with torch.no_grad():
block.
For example, change:
x.data.set_(y)
to:
with torch.no_grad():
x.set_(y)
请问怎样做单条预测
求大神帮忙解答一下,我用您的程序在我电脑上运行,总是会报这个错
Traceback (most recent call last):
File "E:/software/code/sentimentanalysis/chinese_text_cnn/main.py", line 70, in
train_iter, dev_iter = load_dataset(text_field, label_field, args, device=-1, repeat=False, shuffle=True)
File "E:/software/code/sentimentanalysis/chinese_text_cnn/main.py", line 52, in load_dataset
train_dataset, dev_dataset = dataset.get_dataset('data', text_field, label_field)
File "E:\software\code\sentimentanalysis\chinese_text_cnn\dataset.py", line 23, in get_dataset
('text', text_field)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\torchtext\data\dataset.py", line 78, in splits
os.path.join(path, train), **kwargs)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\torchtext\data\dataset.py", line 269, in init
next(reader)
File "C:\Users\Administrator\Anaconda3\lib\site-packages\torchtext\utils.py", line 130, in unicode_csv_reader
csv.field_size_limit(sys.maxsize)
OverflowError: Python int too large to convert to C long
我的电脑系统是win10,python版本是python3.6
Hi I ran the repo on both google colab and windows 10, got same error both times:
help please.
在训练阶段调用完测试函数后(https://github.com/bigboNed3/chinese_text_cnn/blob/master/train.py#L37)是否应该添加一行model.train()
恢复到训练模式呀?
首先非常感谢作者您分享的代码,只是如何编写预测代码呢,我这里不是太懂
Traceback (most recent call last):
File "main.py", line 70, in
train_iter, dev_iter = load_dataset(text_field, label_field, args, device=-1, repeat=False, shuffle=True)
File "main.py", line 57, in load_dataset
text_field.build_vocab(train_dataset, dev_dataset)
File "/home/mli/.pyenv/versions/miniconda-latest/envs/li/lib/python3.7/site-packages/torchtext/data/field.py", line 298, in build_vocab
for x in data:
File "/home/mli/.pyenv/versions/miniconda-latest/envs/li/lib/python3.7/site-packages/torchtext/data/dataset.py", line 154, in getattr
yield getattr(x, attr)
AttributeError: 'Example' object has no attribute 'text'
求大神解答
报错:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [100, 1, 3, 128], but got 3-dimensional input of size [2495, 1, 128] instead
输出size
Batch[9] - loss: 0.666672 acc: 86.7188%(111/128)1 torch.Size([128, 1, 103, 128])
torch.Size([128, 6])
Batch[10] - loss: 0.486642 acc: 90.6250%(116/128)1 torch.Size([2495, 1, 128])
明明是二分类的数据,为何显示class_num=3呢?
你好,chinese_text_cnn/model.py中的第20行中的self.embedding.from_pretrained这个函数在哪里?好像没有找到定义的地方?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.