Comments (6)
请问下,使用的训练代码是什么时候的版本?
从报错来看,是输入words的shape不匹配,可能尝试如下方法:
- 定义
words
的fluid.data
输入为[-1],但实际训练输入的shape为[-1, 1],可以尝试对输入的words调用fluid.layers.squeeze(words, -1)
移除最后多余的shape.
from book.
用的就是这个paddlepaddle/book中的版本
from book.
def infer(use_cuda, params_dirname=None):
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
word_dict = paddle.dataset.imdb.word_dict()
exe = fluid.Executor(place)
inference_scope = fluid.core.Scope()
with fluid.scope_guard(inference_scope):
# Use fluid.io.load_inference_model to obtain the inference program desc,
# the feed_target_names (the names of variables that will be feeded
# data using feed operators), and the fetch_targets (variables that
# we want to obtain data from using fetch operators).
[inferencer, feed_target_names,
fetch_targets] = fluid.io.load_inference_model(params_dirname, exe)
# Setup input by creating LoDTensor to represent sequence of words.
# Here each word is the basic element of the LoDTensor and the shape of
# each word (base_shape) should be [1] since it is simply an index to
# look up for the corresponding word vector.
# Suppose the length_based level of detail (lod) info is set to [[3, 4, 2]],
# which has only one lod level. Then the created LoDTensor will have only
# one higher level structure (sequence of words, or sentence) than the basic
# element (word). Hence the LoDTensor will hold data for three sentences of
# length 3, 4 and 2, respectively.
# Note that lod info should be a list of lists.
reviews_str = [
'read the book forget the movie', 'this is a great movie',
'this is very bad'
]
reviews = [c.split() for c in reviews_str]
UNK = word_dict['<unk>']
lod = []
for c in reviews:
lod.append([np.int64(word_dict.get(words, UNK)) for words in c])
base_shape = [[len(c) for c in lod]]
tensor_words = fluid.create_lod_tensor(lod, base_shape, place)
assert feed_target_names[0] == "words"
results = exe.run(
inferencer,
feed={feed_target_names[0]: tensor_words},
fetch_list=fetch_targets,
return_numpy=False)
np_data = np.array(results[0])
for i, r in enumerate(np_data):
print("Predict probability of ", r[0], " to be positive and ", r[1],
" to be negative for review \'", reviews_str[i], "\'")
这是出现问题的函数,问题出现在 results = exe.run()中
from book.
book 后续可能不会再维护了
最新源码可以参考:
https://github.com/PaddlePaddle/FluidDoc/tree/release/1.8/doc/fluid/user_guides/nlp_case/understand_sentiment#application-model
from book.
谢谢,新版本代码可以正常运行,
from book.
谢谢,新版本代码可以正常运行,
@er11c 请问是否已经解决了您的问题?如果问题已解决,辛苦close下哈~~
from book.
Related Issues (20)
- 06.情感分析示例中,如何得到句子转化成的向量 HOT 1
- book的docker拉下来,一直显示http://127.0.0.1:8888/files/.tools/theme/marked.js无法访问 HOT 2
- docker run -d -p 8888:8888 hub.baidubce.com/paddlepaddle/book后,html显示报错,所有模块都一样 HOT 3
- 07.label_semantic_roles 如何保存 crf_decode, infer 如何 decode? HOT 1
- 基于栈式双向LSTM的情感识别 GPU训练报错 HOT 2
- Network structure not consistent with proposed DCGAN HOT 2
- 06情感分析,案例data type报错 HOT 1
- fit_a_line的示例中,数据的归一化处理时,应该只使用train data。 HOT 1
- 语义序列标注修改输入出现的问题 HOT 2
- 图像分类的代码运行到训练部分报错 HOT 3
- 房价预测代码跑错误 HOT 5
- 机器翻译infer报错 HOT 6
- 01.fit_a_line预测结果差异较大
- 无法访问隐藏文件
- [Call for Contribution] Tutorials for PaddlePaddle 2.0(基于飞桨2.0的应用案例教程建设) HOT 35
- 通过DCGAN实现人脸图像生成
- 认领 题目:通过AutoEncoder实现时序数据异常检测
- test bot HOT 3
- typo in image HOT 1
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 book.