WENGSYX commited on
Commit
2db33ac
·
1 Parent(s): 0a65577

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -3
README.md CHANGED
@@ -1,3 +1,133 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Mastering Symbolic Operations: Augmenting Language Models with Compiled Neural Networks
2
+
3
+
4
+ **Authors**: Yixuan Weng, Minjun Zhu, Fei Xia, Bin Li, Shizhu He, Kang Liu, Jun Zhao 😎
5
+
6
+ **[Contact]** If you have any questions, feel free to contact me via ([email protected]).
7
+
8
+ This repository contains code, models, and other related resources of our paper ["Mastering Symbolic Operations: Augmenting Language Models with Compiled Neural Networks"](https://arxiv.org/abs/2304.01665).
9
+
10
+
11
+ ****
12
+ * [2023/05/19] We have supported the one-click implementation of integration between CoNN and PLM!
13
+ * [2023/05/18] We have published the ["paper-v2"](https://arxiv.org/abs/2304.01665v2)!
14
+ * [2023/04/04] We have used huggingface to release the weight of the CoNN model!
15
+ * [2023/04/04] We have released the code for AutoCoNN!
16
+ * [2023/04/03] We have published the paper!
17
+ * [2023/03/26] We created the Github library!
18
+
19
+ ****
20
+
21
+
22
+
23
+ ### Install
24
+
25
+ ```
26
+ git clone https://github.com/WENGSYX/Neural-Comprehension
27
+ cd Neural-Comprehension
28
+ pip install .
29
+ ```
30
+
31
+ To run neural comprehension, you need to install `PyTorch`, `Transformers`, `jax`, and `tracr`.
32
+ ```
33
+ # https://beta.openai.com/account/api-keys
34
+ export OPENAI_API_KEY=(YOUR OPENAI API KEY)
35
+ ```
36
+
37
+ ### Use AutoCoNN to create your CoNN
38
+
39
+ Please note that setting an OpenAI Key is required to use AutoCoNN (but not necessary if you're just experimenting with neural cognition and CoNN models).
40
+
41
+ ```python
42
+ from NeuralCom.AutoCoNN import AutoCoNN
43
+
44
+ INSTRUCT = 'Create an SOp that is the last letter of a word'
45
+ VOCAB = ['a','b','c','d','e','f','g']
46
+ EXAMPLE = [[['a','b','c'],['c','c','c']],[['b','d'],['d','d']]]
47
+
48
+ auto = AutoCoNN()
49
+ model,tokenizer = auto(instruct=INSTRUCT,vocab=VOCAB,example=EXAMPLE)
50
+ ```
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ ### Use CoNN from huggingface
59
+
60
+ ```python
61
+ from NeuralCom.CoNN.modeling_conn import CoNNModel
62
+ from NeuralCom.CoNN import Tokenizer
63
+
64
+
65
+ model = CoNNModel.from_pretrained('WENGSYX/CoNN_Reverse')
66
+ tokenizer = Tokenizer(model.config.input_encoding_map, model.config.output_encoding_map,model.config.max_position_embeddings)
67
+
68
+ output = model(tokenizer('r e v e r s e').unsqueeze(0))
69
+ print(tokenizer.decode(output.argmax(2)))
70
+ >>> [['bos', 'e', 's', 'r', 'e', 'v', 'e', 'r']]
71
+ ```
72
+
73
+
74
+ ### One-click implementation for Neural-Comprehension
75
+
76
+ ```python
77
+ from transformers import AutoModel,AutoTokenizer,AutoModelForSeq2SeqLM
78
+ from NeuralCom.CoNN.modeling_conn import CoNNModel
79
+ from NeuralCom.CoNN import Tokenizer as CoNNTokenizer
80
+ from NeuralCom.Model import NCModelForCoinFlip
81
+
82
+ PLM = AutoModelForSeq2SeqLM.from_pretrained('WENGSYX/PLM_T5_Base_coin_flip')
83
+ CoNN = CoNNModel.from_pretrained('WENGSYX/CoNN_Parity')
84
+ PLMTokenizer = AutoTokenizer.from_pretrained('WENGSYX/PLM_T5_Base_coin_flip')
85
+ CoNNTokenizer = CoNNTokenizer(CoNN.config.input_encoding_map, CoNN.config.output_encoding_map,CoNN.config.max_position_embeddings)
86
+
87
+ neural_comprehension = NCModelForCoinFlip(PLM, CoNN, PLMTokenizer, CoNNTokenizer).to('cuda:0')
88
+ input_text = "A coin is heads up. Aaron flips the coin. Julius does not flip the coin. Yixuan Weng flip the coin. Minjun Zhu does not flip the coin. Is the coin still heads up?"
89
+ input_tokens_PLM = PLMTokenizer.encode(input_text, return_tensors='pt')
90
+ generated_output = neural_comprehension.generate(input_tokens_PLM.to('cuda:0'))
91
+ generated_text = PLMTokenizer.decode(generated_output, skip_special_tokens=True)
92
+ print(f"Output: {generated_text}")
93
+ ```
94
+
95
+
96
+ #### Huggingface Model
97
+
98
+ In each link, we provide detailed instructions on how to use the CoNN model.
99
+
100
+ | Model Name | Model Size | Model Address |
101
+ | ----------- | ---------- | --------------------------------------------------------- |
102
+ | Parity | 2.2M | [[link]](https://huggingface.co/WENGSYX/CoNN_Parity) |
103
+ | Reverse | 4.3M | [[link]](https://huggingface.co/WENGSYX/CoNN_Reverse) |
104
+ | Last Letter | 62.6K | [[link]](https://huggingface.co/WENGSYX/CoNN_Last_Letter) |
105
+ | Copy | 8.8K | [[link]](https://huggingface.co/WENGSYX/CoNN_Copy) |
106
+ | Add_Carry | 117K | [[link]](https://huggingface.co/WENGSYX/CoNN_Add_Carry) |
107
+ | Sub_Carry | 117K | [[link]](https://huggingface.co/WENGSYX/CoNN_Sub_Carry) |
108
+
109
+ ###### If you have also created some amazing CoNN, you are welcome to share them publicly with us.
110
+
111
+
112
+ ## 🌱 Neural-Comprehension's Roadmap 🌱
113
+
114
+
115
+ Our future plan includes but not limited to :
116
+ - [x] One-click implementation of integration between CoNN and PLM (huggingface)
117
+ - [ ] Combining CoNN with LLM (API-based)
118
+ - [ ] Demo Presentation
119
+
120
+ ### 🙏Cite🙏
121
+
122
+
123
+ ###### If you are interested in our paper, please feel free to cite it.
124
+ ```
125
+ @misc{weng2023mastering,
126
+ title={Mastering Symbolic Operations: Augmenting Language Models with Compiled Neural Networks},
127
+ author={Yixuan Weng and Minjun Zhu and Fei Xia and Bin Li and Shizhu He and Kang Liu and Jun Zhao},
128
+ year={2023},
129
+ eprint={2304.01665},
130
+ archivePrefix={arXiv},
131
+ primaryClass={cs.CL}
132
+ }
133
+ ```