htfhxx / nlp-beginner_solution Goto Github PK
View Code? Open in Web Editor NEW复旦大学邱锡鹏老师推荐的nlp-beginner项目的实现代码
复旦大学邱锡鹏老师推荐的nlp-beginner项目的实现代码
N-gram文本表示方法似乎和TF-IDF并无太大关系。
不知道是不是因为时效的原因, task2
的 dataset
和文件名不完全匹配, 可以修改一下
在我把文件名改成 train.tsv
和 test.tsv
之后
运行这段代码的时候
#构建词典,字符映射到embedding
#TEXT.vocab.vectors 就是词向量
TEXT.build_vocab(train_data, vectors= 'glove.6B.50d', #可以提前下载好
unk_init= lambda x:torch.nn.init.uniform_(x, a=-0.25, b=0.25))
LABEL.build_vocab(train_data)
#得到索引,PAD_TOKEN='<pad>'
PAD_INDEX = TEXT.vocab.stoi[PAD_TOKEN]
TEXT.vocab.vectors[PAD_INDEX] = 0.0
colab上提示这个
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-58-88fe1b0b4be6> in <module>()
3
4 TEXT.build_vocab(train_data, vectors= 'glove.6B.50d', #可以提前下载好
----> 5 unk_init= lambda x:torch.nn.init.uniform_(x, a=-0.25, b=0.25))
6 LABEL.build_vocab(train_data)
7
1 frames
/usr/local/lib/python3.7/dist-packages/torchtext/legacy/data/field.py in build_vocab(self, *args, **kwargs)
290 sources.append(arg)
291 for data in sources:
--> 292 for x in data:
293 if not self.sequential:
294 x = [x]
/usr/local/lib/python3.7/dist-packages/torchtext/legacy/data/dataset.py in __getattr__(self, attr)
152 if attr in self.fields:
153 for x in self.examples:
--> 154 yield getattr(x, attr)
155
156 @classmethod
AttributeError: 'Example' object has no attribute 'Phrase'
不知道是什么原因
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.