Skip to content

Commit

Permalink
#118 fix doc for word vectors url variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Liang Wang committed Feb 6, 2021
1 parent 5a8e3ff commit 21b0d2e
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Chinese Synonyms for Natural Language Processing and Understanding.

# Welcome

```
```bash
pip install -U synonyms
python -c "import synonyms" # download word vectors file
```

兼容 py2 和 py3,当前稳定版本 [v3.x](https://github.com/chatopera/Synonyms/releases)
Expand All @@ -33,12 +34,13 @@ pip install -U synonyms

[#118 词向量文件一直下载不下来?](https://github.com/chatopera/Synonyms/issues/118)可尝试按下述方法设置国内的词向量备份地址:

```
export SYNONYMS_WORD2VEC_BIN_MODEL_ZH_CN=https://gitee.com/chatopera/cskefu/attach_files/610602/download/words.vector.gz
```bash
export SYNONYMS_WORD2VEC_BIN_URL_ZH_CN=https://gitee.com/chatopera/cskefu/attach_files/610602/download/words.vector.gz
pip install -U synonyms
python -c "import synonyms" # download word vectors file
```

其它环境变量介绍见下文。
其它环境变量介绍见下文[Windows cmd 使用 `set SYNONYMS_WORD2VEC_BIN_URL_ZH_CN` 设置环境变量](https://blog.csdn.net/songchunyi/article/details/6413759)

本文档的配置和接口说明面向 python 工具包。

Expand All @@ -55,7 +57,7 @@ pip install -U synonyms

### synonyms#nearby(word [, size = 10])

```
```python
import synonyms
print("人脸: ", synonyms.nearby("人脸"))
print("识别: ", synonyms.nearby("识别"))
Expand All @@ -64,7 +66,7 @@ print("NOT_EXIST: ", synonyms.nearby("NOT_EXIST"))

`synonyms.nearby(WORD [,SIZE])`返回一个元组,元组中包含两项:`([nearby_words], [nearby_words_score])``nearby_words`是 WORD 的近义词们,也以 list 的方式存储,并且按照距离的长度由近及远排列,`nearby_words_score``nearby_words`**对应位置**的词的距离的分数,分数在(0-1)区间内,越接近于 1,代表越相近;`SIZE` 是返回词汇数量,默认 10。比如:

```
```python
synonyms.nearby(人脸, 10) = (
["图片", "图像", "通过观察", "数字图像", "几何图形", "脸部", "图象", "放大镜", "面孔", "Mii"],
[0.597284, 0.580373, 0.568486, 0.535674, 0.531835, 0.530
Expand All @@ -77,15 +79,15 @@ synonyms.nearby(人脸, 10) = (

两个句子的相似度比较

```
```python
sen1 = "发生历史性变革"
sen2 = "发生历史性变革"
r = synonyms.compare(sen1, sen2, seg=True)
```

其中,参数 seg 表示 synonyms.compare 是否对 sen1 和 sen2 进行分词,默认为 True。返回值:[0-1],并且越接近于 1 代表两个句子越相似。

```
```python
旗帜引领方向 vs 道路决定命运: 0.429
旗帜引领方向 vs 旗帜指引道路: 0.93
发生历史性变革 vs 发生历史性变革: 1.0
Expand All @@ -95,7 +97,7 @@ synonyms.nearby(人脸, 10) = (

以友好的方式打印近义词,方便调试,`display(WORD [, SIZE])`调用了 `synonyms#nearby` 方法。

```
```python
>>> synonyms.display("飞机")
'飞机'近义词:
1. 飞机:1.0
Expand All @@ -116,7 +118,7 @@ synonyms.nearby(人脸, 10) = (

获得一个词语的向量,该向量为 numpy 的 array,当该词语是未登录词时,抛出 KeyError 异常。

```
```python
>>> synonyms.v("飞机")
array([-2.412167 , 2.2628384 , -7.0214124 , 3.9381874 , 0.8219283 ,
-3.2809453 , 3.8747153 , -5.217062 , -2.2786229 , -1.2572327 ],
Expand All @@ -127,7 +129,7 @@ array([-2.412167 , 2.2628384 , -7.0214124 , 3.9381874 , 0.8219283 ,

获得一个分词后句子的向量,向量以 BoW 方式组成

```
```python
sentence: 句子是分词后通过空格联合起来
ignore: 是否忽略OOVFalse时,随机生成一个向量
```
Expand All @@ -136,13 +138,13 @@ array([-2.412167 , 2.2628384 , -7.0214124 , 3.9381874 , 0.8219283 ,

中文分词

```
```python
synonyms.seg("中文近义词工具包")
```

分词结果,由两个 list 组成的元组,分别是单词和对应的词性。

```
```python
(['中文', '近义词', '工具包'], ['nz', 'n', 'n'])
```

Expand All @@ -164,7 +166,7 @@ keywords = synonyms.keywords("9月15日以来,台积电、高通、三星等

## Quick Get Start

```
```bash
$ pip install -r Requirements.txt
$ python demo.py
```
Expand Down

0 comments on commit 21b0d2e

Please sign in to comment.