File size: 6,823 Bytes
be0358f
e7787d9
be0358f
e7787d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be0358f
e7787d9
 
a3b557c
e7787d9
 
 
 
 
 
 
 
 
 
99d2ed8
e7787d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3b557c
e7787d9
43988d8
 
 
 
 
 
 
 
 
 
 
 
 
79128e6
43988d8
 
 
 
 
79128e6
43988d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7787d9
 
 
 
 
 
 
79128e6
 
e7787d9
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
language: en
license: mit
datasets:
- RECCON
tags:
- conversational
inference: false
model-index:
- name: Span Extraction
  results:
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (on development set)
      type: train and evaluation dataset
    metrics:
    - name: EMPos
      type: EMPos
      value: 0.3437
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (on development set)
      type: train and evaluation dataset
    metrics:
    - name: F1Pos
      type: F1Pos
      value: 0.6062
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (on development set)
      type: train and evaluation dataset
    metrics:
    - name: F1Neg
      type: F1Neg
      value: 0.8318
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (reported by authors in paper on development set)
      type: train and evaluation dataset
    metrics:
    - name: EMPos
      type: EMPos
      value: 0.3464
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (reported by authors in paper on development set)
      type: train and evaluation dataset
    metrics:
    - name: F1Pos
      type: F1Pos
      value: 0.6000
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (reported by authors in paper on development set)
      type: train and evaluation dataset
    metrics:
    - name: F1Neg
      type: F1Neg
      value: 0.8602
  - task:
      type: conversational
      name: Span-Extraction
    dataset:
      name: RECCON dataset (reported by authors in paper on development set)
      type: train and evaluation dataset
    metrics:
    - name: F1
      type: F1
      value: 0.7571
---

# Causal Span Detection
You can **test the model** at [Casual Span Extraction](https://huggingface.co/spaces/aisingapore/causal-span-extraction) | [SGNLP-Demo](https://sgnlp.aisingapore.net/span-extraction).<br />
If you want to find out more information, please contact us at [email protected].

## Table of Contents
- [Model Details](#model-details)
- [How to Get Started With the Model](#how-to-get-started-with-the-model)
- [Training](#training)
- [Model Parameters](#parameters)
- [Other Information](#other-information)

## Model Details
**Model Name:** Span Extraction
- **Description:** This is a causal span extraction model based on SPANBert which recognises that causes of emotions in conversations. Given 4 sets of inputs: target utterance, target utterance's emotion, evidence utterance and conversational history, it returns arrays of start and end logits which can be postprocessed to obtain the span which caused the emotion in the target utterance.
- **Paper:** Recognizing emotion cause in conversations. arXiv preprint arXiv:2012.11820., Dec 2020.
- **Author(s):** Poria, S., Majumder, N., Hazarika, D., Ghosal, D., Bhardwaj, R., Jian, S.Y.B., Hong, P., Ghosh, R., Roy, A., Chhaya, N., Gelbukh, A. and Mihalcea, R. (2020).
- **URL:** https://arxiv.org/abs/2012.11820/


# How to Get Started With the Model

## Install Python package
SGnlp is an initiative by AI Singapore's NLP Hub. They aim to bridge the gap between research and industry, promote translational research, and encourage adoption of NLP techniques in the industry. <br><br> Various NLP models, other than aspect sentiment analysis are available in the python package. You can try them out at [SGNLP-Demo](https://sgnlp.aisingapore.net/) | [SGNLP-Github](https://github.com/aisingapore/sgnlp).

```python
pip install sgnlp

```

## Examples
For more full code (such as Causal Span Detection), please refer to this [SGNLP-Docs](https://sgnlp.aisingapore.net/docs/model/span_extraction.html). <br> Alternatively, you can also try out the [Casual Span Extraction](https://huggingface.co/spaces/aisingapore/causal-span-extraction) | [SGNLP-Demo](https://sgnlp.aisingapore.net/span-extraction) for Causal-Span-Detection.

Example of Causal Span Detection (for surprise):

```python
from sgnlp.models.span_extraction import (
    RecconSpanExtractionConfig,
    RecconSpanExtractionModel,
    RecconSpanExtractionTokenizer,
    RecconSpanExtractionPreprocessor,
    RecconSpanExtractionPostprocessor,
)

# Load model
config = RecconSpanExtractionConfig.from_pretrained(
    "https://storage.googleapis.com/sgnlp-models/models/reccon_span_extraction/config.json"
)
tokenizer = RecconSpanExtractionTokenizer.from_pretrained(
    "mrm8488/spanbert-finetuned-squadv2"
)
model = RecconSpanExtractionModel.from_pretrained(
    "https://storage.googleapis.com/sgnlp-models/models/reccon_span_extraction/pytorch_model.bin",
    config=config,
)
preprocessor = RecconSpanExtractionPreprocessor(tokenizer)
postprocessor = RecconSpanExtractionPostprocessor()

# Model predict
input_batch = {
    "emotion": ["surprise", "surprise"],
    "target_utterance": [
        "Hi George ! It's good to see you !",
        "Hi George ! It's good to see you !",
    ],
    "evidence_utterance": [
        "Linda ? Is that you ? I haven't seen you in ages !",
        "Hi George ! It's good to see you !",
    ],
    "conversation_history": [
        "Linda ? Is that you ? I haven't seen you in ages ! Hi George ! It's good to see you !",
        "Linda ? Is that you ? I haven't seen you in ages ! Hi George ! It's good to see you !",
    ],
}

tensor_dict, evidences, examples, features = preprocessor(input_batch)
raw_output = model(**tensor_dict)
context, evidence_span, probability = postprocessor(
    raw_output, evidences, examples, features)



```

# Training
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).

#### Training Results
- **Training Time:** ~3 hours for 12 epochs on a single V100 GPU.

# Model Parameters
- **Model Weights:** [link](https://storage.googleapis.com/sgnlp-models/models/reccon_span_extraction/pytorch_model.bin)
- **Model Config:** [link](https://storage.googleapis.com/sgnlp-models/models/reccon_span_extraction/config.json)
- **Model Inputs:** Target utterance, emotion in target utterance, evidence utterance and conversational history.
- **Model Outputs:** Array of start logits and array of end logits. These 2 arrays can be post processed to detemine the start and end of the causal span.
- **Model Size:** ~411MB
- **Model Inference Info:**  ~ 2 sec on Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz.
- **Usage Scenarios:** Recognizing emotion cause for phone support satisfaction.

# Other Information
- **Original Code:** [link](https://github.com/declare-lab/RECCON)