kellywong commited on
Commit
43988d8
1 Parent(s): 99d2ed8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md CHANGED
@@ -113,6 +113,57 @@ pip install sgnlp
113
  ## Examples
114
  For more full code (such as Causal Span Detection), please refer to this [SGNLP-Github](https://github.com/aisingapore/sgnlp). <br> Alternatively, you can also try out the [SGNLP-Demo](https://sgnlp.aisingapore.net/span-extraction) for Causal-Span-Detection.
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  # Training
117
  The train and evaluation datasets were derived from the RECCON dataset. The full dataset can be downloaded from the author's [github repository](https://github.com/declare-lab/RECCON/tree/main/data).
118
 
 
113
  ## Examples
114
  For more full code (such as Causal Span Detection), please refer to this [SGNLP-Github](https://github.com/aisingapore/sgnlp). <br> Alternatively, you can also try out the [SGNLP-Demo](https://sgnlp.aisingapore.net/span-extraction) for Causal-Span-Detection.
115
 
116
+ Example of Causal Span Detection (for surprise):
117
+
118
+ ```python
119
+ from sgnlp.models.span_extraction import (
120
+ RecconSpanExtractionConfig,
121
+ RecconSpanExtractionModel,
122
+ RecconSpanExtractionTokenizer,
123
+ RecconSpanExtractionPreprocessor,
124
+ RecconSpanExtractionPostprocessor,
125
+ )
126
+
127
+ # Load model
128
+ config = RecconSpanExtractionConfig.from_pretrained(
129
+ "https://storage.googleapis.com/sgnlp/models/reccon_span_extraction/config.json"
130
+ )
131
+ tokenizer = RecconSpanExtractionTokenizer.from_pretrained(
132
+ "mrm8488/spanbert-finetuned-squadv2"
133
+ )
134
+ model = RecconSpanExtractionModel.from_pretrained(
135
+ "https://storage.googleapis.com/sgnlp/models/reccon_span_extraction/pytorch_model.bin",
136
+ config=config,
137
+ )
138
+ preprocessor = RecconSpanExtractionPreprocessor(tokenizer)
139
+ postprocessor = RecconSpanExtractionPostprocessor()
140
+
141
+ # Model predict
142
+ input_batch = {
143
+ "emotion": ["surprise", "surprise"],
144
+ "target_utterance": [
145
+ "Hi George ! It's good to see you !",
146
+ "Hi George ! It's good to see you !",
147
+ ],
148
+ "evidence_utterance": [
149
+ "Linda ? Is that you ? I haven't seen you in ages !",
150
+ "Hi George ! It's good to see you !",
151
+ ],
152
+ "conversation_history": [
153
+ "Linda ? Is that you ? I haven't seen you in ages ! Hi George ! It's good to see you !",
154
+ "Linda ? Is that you ? I haven't seen you in ages ! Hi George ! It's good to see you !",
155
+ ],
156
+ }
157
+
158
+ tensor_dict, evidences, examples, features = preprocessor(input_batch)
159
+ raw_output = model(**tensor_dict)
160
+ context, evidence_span, probability = postprocessor(
161
+ raw_output, evidences, examples, features)
162
+
163
+
164
+
165
+ ```
166
+
167
  # Training
168
  The train and evaluation datasets were derived from the RECCON dataset. The full dataset can be downloaded from the author's [github repository](https://github.com/declare-lab/RECCON/tree/main/data).
169