Macropodus commited on
Commit
85f8332
1 Parent(s): d086268

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +109 -3
README.md CHANGED
@@ -1,3 +1,109 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # near-synonym
2
+ >>> near-synonym, 中文反义词/近义词(antonym/synonym)工具包.
3
+
4
+ # 一、安装
5
+ ```
6
+ 0. 注意事项
7
+ 默认不指定numpy版本(标准版numpy==1.20.4)
8
+ 标准版本的依赖包详见 requirements-all.txt
9
+
10
+ 1. 通过PyPI安装
11
+ pip install near-synonym
12
+ 使用镜像源, 如:
13
+ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple near-synonym
14
+ ```
15
+
16
+ # 二、使用方式
17
+
18
+ ## 2.1 快速使用, 反义词, 近义词
19
+ ```python3
20
+ import near_synonym
21
+
22
+ word = "喜欢"
23
+ word_antonyms = near_synonym.antonyms(word)
24
+ word_synonyms = near_synonym.synonyms(word)
25
+ print("反义词:")
26
+ print(word_antonyms)
27
+ print("近义词:")
28
+ print(word_synonyms)
29
+ """
30
+ 反义词:
31
+ [('讨厌', 0.6954), ('不爱', 0.6714), ('偏爱', 0.6676), ('太爱', 0.6472), ('花心', 0.6421), ('在乎', 0.6395), ('好感', 0.6378), ('酷爱', 0.634)]
32
+ 近义词:
33
+ [('最爱', 0.84), ('爱好', 0.8274), ('超爱', 0.8213), ('爱上', 0.8107), ('爱玩', 0.8039), ('狂爱', 0.798), ('大胆', 0.7852), ('喜欢上', 0.7826)]
34
+ 请输入word:
35
+ """
36
+ ```
37
+
38
+
39
+ ## 2.2 详细使用
40
+ ```python3
41
+ import near_synonym
42
+
43
+ word = "喜欢"
44
+ word_antonyms = near_synonym.antonyms(word, topk=8, annk=256, annk_cpu=128, batch_size=32,
45
+ rate_ann=0.4, rate_sim=0.4, rate_len=0.2, rounded=4, is_debug=False)
46
+ print("反义词:")
47
+ print(word_antonyms)
48
+ # 速度很慢, 召回数量annk_cpu/annk可以调小
49
+ ```
50
+
51
+
52
+ # 三、技术原理
53
+ ## 3.1 技术详情
54
+ ```
55
+ near-synonym, 中文反义词/近义词工具包.
56
+ 流程: Word2vec -> ANN -> NLI -> Length
57
+
58
+ # Word2vec, 词向量, 使用skip-ngram的词向量;
59
+ # ANN, 近邻搜索, 使用annoy检索召回;
60
+ # NLI, 自然语言推断, 使用Roformer-sim的v2版本, 区分反义词/近义词;
61
+ # Length, 惩罚项, 词语的文本长度惩罚;
62
+ ```
63
+
64
+ ## 3.2 TODO
65
+ ```
66
+ 1. 使用大模型构建语料, 训练小的NLI模型, 替换roformer-sim-ft.
67
+ ```
68
+
69
+ # 四、对比
70
+ ## 4.1 相似度比较
71
+ | 词语 | 2016词林改进版 | 知网hownet | Synonyms | near-synonym |
72
+ |--------------|-----------------|---------------|-----------------| ----------------- |
73
+ | "轿车","汽车" | 0.82 | 1.0 | 0.73 | 0.86 |
74
+ | "宝石","宝物" | 0.83 | 0.17 | 0.71 | 0.81 |
75
+ | "旅游","游历" | 1.0 | 1.0 | 0.59 | 0.72 |
76
+ | "男孩子","小伙子" | 0.81 | 1.0 | 0.88 | 0.83 |
77
+ | "海岸","海滨" | 0.94 | 1.0 | 0.68 | 0.9 |
78
+ | "庇护所","精神病院" | 0.96 | 0.58 | 0.64 | 0.62 |
79
+ | "魔术师","巫师" | 0.85 | 0.58 | 0.66 | 0.78 |
80
+ | "火炉","炉灶" | 1.0 | 1.0 | 0.81 | 0.83 |
81
+ | "中午","正午" | 0.98 | 0.58 | 0.85 | 0.88 |
82
+ | "食物","水果" | 0.35 | 0.14 | 0.74 | 0.82 |
83
+ | "鸟","公鸡" | 0.64 | 1.0 | 0.67 | 0.72 |
84
+ | "鸟","鹤" | 0.1 | 1.0 | 0.64 | 0.81 |
85
+ | "工具","器械" | 0.53 | 1.0 | 0.62 | 0.75 |
86
+ | "兄弟","和尚" | 0.37 | 0.80 | 0.59 | 0.7 |
87
+ | "起重机","器械" | 0.53 | 0.35 | 0.61 | 0.65 |
88
+ 注:2016词林改进版/知网hownet/Synonyms数据、分数来源于[chatopera/Synonyms](https://github.com/chatopera/Synonyms)。同义词林及知网数据、分数的次级来源为[liuhuanyong/SentenceSimilarity](https://github.com/liuhuanyong/SentenceSimilarity)。
89
+
90
+
91
+ # 五、参考
92
+ - [https://ai.tencent.com/ailab/nlp/en/index.html](https://ai.tencent.com/ailab/nlp/en/index.html)
93
+ - [https://github.com/ZhuiyiTechnology/roformer-sim](https://github.com/ZhuiyiTechnology/roformer-sim)
94
+ - [https://github.com/liuhuanyong/SentenceSimilarity](https://github.com/liuhuanyong/SentenceSimilarity)
95
+ - [https://github.com/yongzhuo/Macropodus](https://github.com/yongzhuo/Macropodus)
96
+ - [https://github.com/chatopera/Synonyms](https://github.com/chatopera/Synonyms)
97
+
98
+ # Reference
99
+ For citing this work, you can refer to the present GitHub project. For example, with BibTeX:
100
+ ```
101
+ @misc{Macropodus,
102
+ howpublished = {https://github.com/yongzhuo/near-synonym},
103
+ title = {near-synonym},
104
+ author = {Yongzhuo Mo},
105
+ publisher = {GitHub},
106
+ year = {2024}
107
+ }
108
+ ```
109
+