Comments (2)
自己写了个函数:
if args.status == 'predict':
line = "union select or 1=1"
vocab = build_vocab(train_path, args.word, args.vocab_size, args.min_freq)
n_vocab = len(vocab)
model = Model(n_vocab, args.num_classes, args.embed, args.num_filters, args.filter_sizes, args.dropout).to(device)
print(model.parameters)
# print(model.predict(vocab, args.word, line))
#predict(model, vocab, args.word, args.max_sequence_length, line, '1', device)
if args.word:
tokenizer = lambda x: x.split(' ')
else:
tokenizer = lambda x: [y for y in x]
content = tokenizer(line)
data = [vocab[x] for x in content if x in vocab]
data = kr.preprocessing.sequence.pad_sequences([data], 32)
tests = [np.asarray(data)]
test_batch = Variable(torch.LongTensor(tests))
# 其一
predict = model(test_batch).data.max(1, keepdim=True)[1]
label = predict[0][0]
print(label)
#其二
outputs = model(test_batch)
predic = torch.max(outputs.data, 1)[1].cpu().numpy()
print(predic)
from chinese-text-classification-pytorch.
自己写了个函数:
if args.status == 'predict': line = "union select or 1=1" vocab = build_vocab(train_path, args.word, args.vocab_size, args.min_freq) n_vocab = len(vocab) model = Model(n_vocab, args.num_classes, args.embed, args.num_filters, args.filter_sizes, args.dropout).to(device) print(model.parameters) # print(model.predict(vocab, args.word, line)) #predict(model, vocab, args.word, args.max_sequence_length, line, '1', device) if args.word: tokenizer = lambda x: x.split(' ') else: tokenizer = lambda x: [y for y in x] content = tokenizer(line) data = [vocab[x] for x in content if x in vocab] data = kr.preprocessing.sequence.pad_sequences([data], 32) tests = [np.asarray(data)] test_batch = Variable(torch.LongTensor(tests)) # 其一 predict = model(test_batch).data.max(1, keepdim=True)[1] label = predict[0][0] print(label) #其二 outputs = model(test_batch) predic = torch.max(outputs.data, 1)[1].cpu().numpy() print(predic)
在本项目中用不了
from chinese-text-classification-pytorch.
Related Issues (20)
- Text_RCNN文本分类效果
- 使用自己的数据集出现问题 HOT 1
- FastText的n_gram_vocab HOT 1
- 一个文本要是有多个标签要怎么用这个模型呢 HOT 3
- 用模型进行预测,该怎么实现呢 HOT 2
- 如果想改成英文数据,都需要修改什么呢
- transformer HOT 2
- 可以写一个单条预测的接口嘛?
- RuntimeError: GET was unable to find an engine to execute this computation
- 是否有文本长度限制 HOT 1
- Bi-LSTM问题
- 是否是没有进行分词?
- 选择题如何定制输入
- 词向量训练问题
- [BUG] TextCNN训练速度很慢
- 请问为何TextCNN的一个iter为什么要十几分钟,而TextRNN就很快,一个epoch不到一分钟? HOT 2
- 网络结构中Model加载预训练词向量的疑问
- 这个仓是不是没有维护了呀?
- AttributeError: 'Config' object has no attribute 'n_gram_vocab' HOT 1
- 模型预测类 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chinese-text-classification-pytorch.