File size: 1,468 Bytes
d99ec6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language:
- en

tags:
- formality transfer

licenses:
- cc-by-nc-sa
---
LEWIP-informal model is designed to transfer formal text into informal keeping the important slots from the source text. The slots can be either pre-defined or detected automatically.

The model is based on LEWIP (Levenshtein editing with the parallel corpus). It exploits the ability of T5 model to fill the slots between the known texts with undefined number of tokens. 

## How to use

### Installation

```python
!pip install lewip_informal
```

### Generating content preserving informal paraphrases

#### When the important entities are known in advance

```python
from lewip_informal import LEWIP
model = LEWIP(use_cuda = True)
text = 'I want to go to NY'
ent = ['NY']
model.generate(text, ent)
# expected output 'i wanna go to NY'
```

#### When the important entities are NOT known in advance

In case the important slots are not known, they are automatically detected with auxiliary tagger model. 

```python
from lewip_informal import LEWIP
model = LEWIP(predefined_entities = False, use_cuda = True)
text = 'I really want to travel to NY'
model.generate(text)
# expected output 'I really want to go to NY'
```

You may want to have a look at the slots which were labeled as important by the tagger. Use 'show_template' variable

```python

model.generate(text, show_template = True)
# expected output 
# I <extra_id_0> want to <extra_id_1> to NY
# 'I really want to go to NY'

```