Skip to content

Commit 047b8b6

Browse files
authored
Add en vector for the embedding
* add more English embedding name * fix doc bug * delete useless description * add comments of TokenEmbedding * add embedding model info
1 parent 69ccb4c commit 047b8b6

File tree

4 files changed

+206
-26
lines changed

4 files changed

+206
-26
lines changed

PaddleNLP/docs/embeddings.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
- [Embedding 模型汇总](#embedding-模型汇总)
2+
- [中文词向量](#中文词向量)
3+
- [英文词向量](#英文词向量)
4+
- [GloVe](#glove)
5+
- [FastText](#fasttext)
6+
- [模型信息](#模型信息)
7+
- [致谢](#致谢)
8+
- [参考论文](#参考论文)
9+
110
# Embedding 模型汇总
211

312
PaddleNLP提供多个开源的预训练Embedding模型,用户仅需在使用`paddlenlp.embeddings.TokenEmbedding`时,指定预训练模型的名称,即可加载相对应的预训练模型。以下为PaddleNLP所支持的预训练Embedding模型,其名称用作`paddlenlp.embeddings.TokenEmbedding`的参数。命名方式为:\${训练模型}.\${语料}.\${词向量类型}.\${co-occurrence type}.dim\${维度}。训练模型有三种,分别是Word2Vec(w2v, 使用skip-gram模型训练), GloVe(glove)和FastText(fasttext)。
@@ -42,11 +51,91 @@ PaddleNLP提供多个开源的预训练Embedding模型,用户仅需在使用`p
4251

4352
## 英文词向量
4453

45-
待更新。
54+
### GloVe
55+
56+
| 语料 | 25维 | 50维 | 100维 | 200维 | 300 维 |
57+
| ----------------- | ------ | ------ | ------ | ------ | ------ |
58+
| Wiki2014 + GigaWord || glove.wiki2014-gigaword.target.word-word.dim50.en | glove.wiki2014-gigaword.target.word-word.dim100.en | glove.wiki2014-gigaword.target.word-word.dim200.en | glove.wiki2014-gigaword.target.word-word.dim300.en |
59+
| Twitter | glove.twitter.target.word-word.dim25.en | glove.twitter.target.word-word.dim50.en | glove.twitter.target.word-word.dim100.en | glove.twitter.target.word-word.dim200.en ||
60+
61+
### FastText
62+
63+
| 语料 | 名称 |
64+
|------|------|
65+
| Wiki2017 | fasttext.wiki-news.target.word-word.dim300.en |
66+
| Crawl | fasttext.crawl.target.word-word.dim300.en |
67+
68+
## 模型信息
69+
70+
| 模型 | 文件大小 | 词表大小 |
71+
|-----|---------|---------|
72+
| w2v.baidu_encyclopedia.target.word-word.dim300 | 678.21 MB | 635965 |
73+
| w2v.baidu_encyclopedia.target.word-character.char1-1.dim300 | 679.15 MB | 636038 |
74+
| w2v.baidu_encyclopedia.target.word-character.char1-2.dim300 | 679.30 MB | 636038 |
75+
| w2v.baidu_encyclopedia.target.word-character.char1-4.dim300 | 679.51 MB | 636038 |
76+
| w2v.baidu_encyclopedia.target.word-ngram.1-2.dim300 | 679.48 MB | 635977 |
77+
| w2v.baidu_encyclopedia.target.word-ngram.1-3.dim300 | 671.27 MB | 628669 |
78+
| w2v.baidu_encyclopedia.target.word-ngram.2-2.dim300 | 7.28 GB | 6969069 |
79+
| w2v.baidu_encyclopedia.target.word-wordLR.dim300 | 678.22 MB | 635958 |
80+
| w2v.baidu_encyclopedia.target.word-wordPosition.dim300 | 679.32 MB | 636038 |
81+
| w2v.baidu_encyclopedia.target.bigram-char.dim300 | 679.29 MB | 635976 |
82+
| w2v.baidu_encyclopedia.context.word-word.dim300 | 677.74 MB | 635952 |
83+
| w2v.baidu_encyclopedia.context.word-character.char1-1.dim300 | 678.65 MB | 636200 |
84+
| w2v.baidu_encyclopedia.context.word-character.char1-2.dim300 | 844.23 MB | 792631 |
85+
| w2v.baidu_encyclopedia.context.word-character.char1-4.dim300 | 1.16 GB | 1117461 |
86+
| w2v.baidu_encyclopedia.context.word-ngram.1-2.dim300 | 7.25 GB | 6967598 |
87+
| w2v.baidu_encyclopedia.context.word-ngram.1-3.dim300 | 5.21 GB | 5000001 |
88+
| w2v.baidu_encyclopedia.context.word-ngram.2-2.dim300 | 7.26 GB | 6968998 |
89+
| w2v.baidu_encyclopedia.context.word-wordLR.dim300 | 1.32 GB | 1271031 |
90+
| w2v.baidu_encyclopedia.context.word-wordPosition.dim300 | 6.47 GB | 6293920 |
91+
| w2v.wiki.target.bigram-char.dim300 | 375.98 MB | 352274 |
92+
| w2v.wiki.target.word-char.dim300 | 375.52 MB | 352223 |
93+
| w2v.wiki.target.word-word.dim300 | 374.95 MB | 352219 |
94+
| w2v.wiki.target.word-bigram.dim300 | 375.72 MB | 352219 |
95+
| w2v.people_daily.target.bigram-char.dim300 | 379.96 MB | 356055 |
96+
| w2v.people_daily.target.word-char.dim300 | 379.45 MB | 355998 |
97+
| w2v.people_daily.target.word-word.dim300 | 378.93 MB | 355989 |
98+
| w2v.people_daily.target.word-bigram.dim300 | 379.68 MB | 355991 |
99+
| w2v.weibo.target.bigram-char.dim300 | 208.24 MB | 195199 |
100+
| w2v.weibo.target.word-char.dim300 | 208.03 MB | 195204 |
101+
| w2v.weibo.target.word-word.dim300 | 207.94 MB | 195204 |
102+
| w2v.weibo.target.word-bigram.dim300 | 208.19 MB | 195204 |
103+
| w2v.sogou.target.bigram-char.dim300 | 389.81 MB | 365112 |
104+
| w2v.sogou.target.word-char.dim300 | 389.89 MB | 365078 |
105+
| w2v.sogou.target.word-word.dim300 | 388.66 MB | 364992 |
106+
| w2v.sogou.target.word-bigram.dim300 | 388.66 MB | 364994 |
107+
| w2v.zhihu.target.bigram-char.dim300 | 277.35 MB | 259755 |
108+
| w2v.zhihu.target.word-char.dim300 | 277.40 MB | 259940 |
109+
| w2v.zhihu.target.word-word.dim300 | 276.98 MB | 259871 |
110+
| w2v.zhihu.target.word-bigram.dim300 | 277.53 MB | 259885 |
111+
| w2v.financial.target.bigram-char.dim300 | 499.52 MB | 467163 |
112+
| w2v.financial.target.word-char.dim300 | 499.17 MB | 467343 |
113+
| w2v.financial.target.word-word.dim300 | 498.94 MB | 467324 |
114+
| w2v.financial.target.word-bigram.dim300 | 499.54 MB | 467331 |
115+
| w2v.literature.target.bigram-char.dim300 | 200.69 MB | 187975 |
116+
| w2v.literature.target.word-char.dim300 | 200.44 MB | 187980 |
117+
| w2v.literature.target.word-word.dim300 | 200.28 MB | 187961 |
118+
| w2v.literature.target.word-bigram.dim300 | 200.59 MB | 187962 |
119+
| w2v.sikuquanshu.target.word-word.dim300 | 20.70 MB | 19529 |
120+
| w2v.sikuquanshu.target.word-bigram.dim300 | 20.77 MB | 19529 |
121+
| w2v.mixed-large.target.word-char.dim300 | 1.35 GB | 1292552 |
122+
| w2v.mixed-large.target.word-word.dim300 | 1.35 GB | 1292483 |
123+
| glove.wiki2014-gigaword.target.word-word.dim50.en | 73.45 MB | 400002 |
124+
| glove.wiki2014-gigaword.target.word-word.dim100.en | 143.30 MB | 400002 |
125+
| glove.wiki2014-gigaword.target.word-word.dim200.en | 282.97 MB | 400002 |
126+
| glove.wiki2014-gigaword.target.word-word.dim300.en | 422.83 MB | 400002 |
127+
| glove.twitter.target.word-word.dim25.en | 116.92 MB | 1193516 |
128+
| glove.twitter.target.word-word.dim50.en | 221.64 MB | 1193516 |
129+
| glove.twitter.target.word-word.dim100.en | 431.08 MB | 1193516 |
130+
| glove.twitter.target.word-word.dim200.en | 848.56 MB | 1193516 |
131+
| fasttext.wiki-news.target.word-word.dim300.en | 541.63 MB | 999996 |
132+
| fasttext.crawl.target.word-word.dim300.en | 1.19 GB | 2000002 |
46133

47134
## 致谢
48-
- 感谢 [Chinese-Word-Vectors](https://github.com/Embedding/Chinese-Word-Vectors)提供Word2Vec中文Embedding来源
135+
- 感谢 [Chinese-Word-Vectors](https://github.com/Embedding/Chinese-Word-Vectors)提供Word2Vec中文Embedding预训练模型,[GloVe Project](https://nlp.stanford.edu/projects/glove)提供的GloVe英文Embedding预训练模型,[FastText Project](https://fasttext.cc/docs/en/english-vectors.html)提供的fasttext英文预训练模型
49136

50137
## 参考论文
51138
- Li, Shen, et al. "Analogical reasoning on chinese morphological and semantic relations." arXiv preprint arXiv:1805.06504 (2018).
52139
- Qiu, Yuanyuan, et al. "Revisiting correlations between intrinsic and extrinsic evaluations of word embeddings." Chinese Computational Linguistics and Natural Language Processing Based on Naturally Annotated Big Data. Springer, Cham, 2018. 209-221.
140+
- Jeffrey Pennington, Richard Socher, and Christopher D. Manning. 2014. GloVe: Global Vectors for Word Representation.
141+
- T. Mikolov, E. Grave, P. Bojanowski, C. Puhrsch, A. Joulin. Advances in Pre-Training Distributed Word Representations

PaddleNLP/examples/word_embedding/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 简介
44

5-
PaddleNLP已预置多个公开的预训练Embedding,用户可以通过使用`paddle.embeddings.TokenEmbedding`接口加载预训练Embedding,从而提升训练效果。以下通过文本分类训练的例子展示`paddle.embeddings.TokenEmbedding`对训练提升的效果。
5+
PaddleNLP已预置多个公开的预训练Embedding,用户可以通过使用`paddlenlp.embeddings.TokenEmbedding`接口加载预训练Embedding,从而提升训练效果。以下通过文本分类训练的例子展示`paddlenlp.embeddings.TokenEmbedding`对训练提升的效果。
66

77

88
## 快速开始
@@ -13,17 +13,14 @@ PaddleNLP已预置多个公开的预训练Embedding,用户可以通过使用`p
1313

1414
本项目依赖于 PaddlePaddle 2.0 及以上版本,请参考 [安装指南](http://www.paddlepaddle.org/#quick-start) 进行安装
1515

16-
* PaddleNLP 安装
17-
18-
```shell
19-
pip install paddlenlp
20-
```
21-
2216
* 环境依赖
2317

24-
本项目依赖于jieba分词,请在运行本项目之前,安装jieba,如`pip install -U jieba`
18+
- python >= 3.6
19+
- paddlepaddle-gpu >= 2.0.0-rc1
2520

26-
Python的版本要求 3.6+,其它环境请参考 PaddlePaddle [安装说明](https://www.paddlepaddle.org.cn/install/quick/zh/2.0rc-linux-docker) 部分的内容
21+
```
22+
pip install paddlenlp==2.0.0b
23+
```
2724

2825
### 下载词表
2926

@@ -35,24 +32,27 @@ wget https://paddlenlp.bj.bcebos.com/data/dict.txt
3532

3633
### 启动训练
3734

38-
我们以中文情感分类公开数据集ChnSentiCorp为示例数据集,可以运行下面的命令,在训练集(train.tsv)上进行模型训练,并在开发集(dev.tsv)验证。实验输出的日志保存在use_token_embedding.txt和use_normal_embedding.txt。使用PaddlePaddle框架的Embedding在ChnSentiCorp下非常容易过拟合,因此调低了它的学习率
35+
我们以中文情感分类公开数据集ChnSentiCorp为示例数据集,可以运行下面的命令,在训练集(train.tsv)上进行模型训练,并在验证集(dev.tsv)验证。
3936

4037
CPU 启动:
4138

4239
```
43-
nohup python train.py --vocab_path='./dict.txt' --use_gpu=False --lr=5e-4 --batch_size=64 --epochs=20 --use_token_embedding=True --vdl_dir='./vdl_dir' >use_token_embedding.txt 2>&1 &
40+
# 使用paddlenlp.embeddings.TokenEmbedding
41+
python train.py --vocab_path='./dict.txt' --use_gpu=False --lr=5e-4 --batch_size=64 --epochs=20 --use_token_embedding=True --vdl_dir='./vdl_dir'
4442
45-
nohup python train.py --vocab_path='./dict.txt' --use_gpu=False --lr=1e-4 --batch_size=64 --epochs=20 --use_token_embedding=False --vdl_dir='./vdl_dir'>use_normal_embedding.txt 2>&1 &
43+
# 使用paddle.nn.Embedding
44+
python train.py --vocab_path='./dict.txt' --use_gpu=False --lr=1e-4 --batch_size=64 --epochs=20 --use_token_embedding=False --vdl_dir='./vdl_dir'
4645
```
4746

4847
GPU 启动:
4948
```
5049
export CUDA_VISIBLE_DEVICES=0
5150
52-
nohup python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=5e-4 --batch_size=64 --epochs=20 --use_token_embedding=True --vdl_dir='./vdl_dir' > use_token_embedding.txt 2>&1 &
51+
# 使用paddlenlp.embeddings.TokenEmbedding
52+
python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=5e-4 --batch_size=64 --epochs=20 --use_token_embedding=True --vdl_dir='./vdl_dir'
5353
54-
# 如显存不足,可以先等第一个训练完成再启动该训练
55-
nohup python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=1e-4 --batch_size=64 --epochs=20 --use_token_embedding=False --vdl_dir='./vdl_dir' > use_normal_embedding.txt 2>&1 &
54+
# 使用paddle.nn.Embedding
55+
python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=1e-4 --batch_size=64 --epochs=20 --use_token_embedding=False --vdl_dir='./vdl_dir'
5656
```
5757

5858
以上参数表示:
@@ -62,7 +62,7 @@ nohup python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=1e-4 --batch
6262
* `lr`: 学习率, 默认为5e-4。
6363
* `batch_size`: 运行一个batch大小,默认为64。
6464
* `epochs`: 训练轮次,默认为5。
65-
* `use_token_embedding`: 是否使用PaddleNLP的TokenEmbedding,默认为True。
65+
* `use_token_embedding`: 是否使用`paddlenlp.embeddings.TokenEmbedding`,默认为True。
6666
* `vdl_dir`: VisualDL日志目录。训练过程中的VisualDL信息会在该目录下保存。默认为`./vdl_dir`
6767

6868
该脚本还提供以下参数:
@@ -76,14 +76,14 @@ nohup python train.py --vocab_path='./dict.txt' --use_gpu=True --lr=1e-4 --batch
7676
推荐使用VisualDL查看实验对比。以下为VisualDL的启动命令,其中logdir参数指定的目录需要与启动训练时指定的`vdl_dir`相同。(更多VisualDL的用法,可参考[VisualDL使用指南](https://github.com/PaddlePaddle/VisualDL#2-launch-panel)
7777

7878
```
79-
nohup visualdl --logdir ./vdl_dir --port 8888 --host 0.0.0.0 &
79+
visualdl --logdir ./vdl_dir --port 8888 --host 0.0.0.0
8080
```
8181

8282
### 训练效果对比
8383

8484
在Chrome浏览器输入 `ip:8888` (ip为启动VisualDL机器的IP)。
8585

86-
以下为示例实验效果对比图,蓝色是使用`paddle.embeddings.TokenEmbedding`进行的实验,绿色是使用没有加载预训练模型的Embedding进行的实验。可以看到,使用`paddle.embeddings.TokenEmbedding`的训练,其验证acc变化趋势上升,并收敛于0.90左右,收敛后相对平稳,不容易过拟合。而没有使用`paddle.embeddings.TokenEmbedding`的训练,其验证acc变化趋势向下,并收敛于0.86左右。从示例实验可以观察到,使用`paddle.embedding.TokenEmbedding`能提升训练效果。
86+
以下为示例实验效果对比图,蓝色是使用`paddlenlp.embeddings.TokenEmbedding`进行的实验,绿色是使用没有加载预训练模型的Embedding进行的实验。可以看到,使用`paddlenlp.embeddings.TokenEmbedding`的训练,其验证acc变化趋势上升,并收敛于0.90左右,收敛后相对平稳,不容易过拟合。而没有使用`paddlenlp.embeddings.TokenEmbedding`的训练,其验证acc变化趋势向下,并收敛于0.86左右。从示例实验可以观察到,使用`paddlenlp.embedding.TokenEmbedding`能提升训练效果。
8787

8888
Eval Acc:
8989

@@ -95,8 +95,10 @@ Eval Acc:
9595
| paddelnlp.embeddings.TokenEmbedding | 0.9082 |
9696

9797
## 致谢
98-
- 感谢 [Chinese-Word-Vectors](https://github.com/Embedding/Chinese-Word-Vectors)提供Word2Vec中文Embedding来源
98+
- 感谢 [Chinese-Word-Vectors](https://github.com/Embedding/Chinese-Word-Vectors)提供Word2Vec中文Embedding预训练模型,[GloVe Project](https://nlp.stanford.edu/projects/glove)提供的GloVe英文Embedding预训练模型,[FastText Project](https://fasttext.cc/docs/en/english-vectors.html)提供的fasttext英文预训练模型
9999

100100
## 参考论文
101101
- Li, Shen, et al. "Analogical reasoning on chinese morphological and semantic relations." arXiv preprint arXiv:1805.06504 (2018).
102102
- Qiu, Yuanyuan, et al. "Revisiting correlations between intrinsic and extrinsic evaluations of word embeddings." Chinese Computational Linguistics and Natural Language Processing Based on Naturally Annotated Big Data. Springer, Cham, 2018. 209-221.
103+
- Jeffrey Pennington, Richard Socher, and Christopher D. Manning. 2014. GloVe: Global Vectors for Word Representation.
104+
- T. Mikolov, E. Grave, P. Bojanowski, C. Puhrsch, A. Joulin. Advances in Pre-Training Distributed Word Representations

PaddleNLP/paddlenlp/embeddings/constant.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,18 @@
8383
"w2v.sikuquanshu.target.word-bigram.dim300",
8484
# Mix-large
8585
"w2v.mixed-large.target.word-char.dim300",
86-
"w2v.mixed-large.target.word-word.dim300"
86+
"w2v.mixed-large.target.word-word.dim300",
87+
88+
# GloVe
89+
"glove.wiki2014-gigaword.target.word-word.dim50.en",
90+
"glove.wiki2014-gigaword.target.word-word.dim100.en",
91+
"glove.wiki2014-gigaword.target.word-word.dim200.en",
92+
"glove.wiki2014-gigaword.target.word-word.dim300.en",
93+
"glove.twitter.target.word-word.dim25.en",
94+
"glove.twitter.target.word-word.dim50.en",
95+
"glove.twitter.target.word-word.dim100.en",
96+
"glove.twitter.target.word-word.dim200.en",
97+
# FastText
98+
"fasttext.wiki-news.target.word-word.dim300.en",
99+
"fasttext.crawl.target.word-word.dim300.en"
87100
]

0 commit comments

Comments
 (0)