File size: 3,389 Bytes
e372e1c a051749 0dd12ec 5e65ba5 0dd12ec f049c18 0dd12ec |
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 |
---
license: mit
language:
- en
---
# Personalized Text Generation with Fine-Grained Linguistic Control
## Model Description
## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('balhafni/personalized-gen')
tokenizer = AutoTokenizer.from_pretrained('balhafni/personalized-gen')
ling_atts = {"ADJ": "5-8", "ADP": "10-11", "ADV": "6-8", "AUX": "9-11",
"CONJ": "2-4", "DET": "7-10", "FKGL": "5-6", "NOUN": "11-18",
"NUM": "2-3", "PART": "4-5", "PRON": "14-17", "PROPN": "8-11",
"PUNCT": "22-25", "ROOT": "9-10", "SCONJ": "3-4", "VERB": "16-20",
"acl": "0-1", "acomp": "1-2", "advcl": "2-3", "advmod": "7-9",
"amod": "3-6", "appos": "0-1", "attr": "1-2", "attribution": "2-3",
"aux": "6-7", "auxpass": "0-1", "case": "0-1", "cc": "2-4",
"ccomp": "3-4", "compound": "5-6", "conj": "2-4", "contrast": "0-1",
"det": "7-10", "dobj": "6-7", "domain": "blog",
"elaboration": "10-12", "mark": "2-3", "neg": "2-3", "nmod": "0-1",
"npadvmod": "1-2", "nsubj": "13-16", "nsubjpass": "0-1",
"num_sents": "9-10", "num_tokens": "118-139", "nummod": "1-2",
"pcomp": "0-1", "pobj": "8-10", "poss": "2-3", "prep": "9-10"
}
prompt = ("Today's lunch was a layered entree, consisting of, "
"shredded lettuce and popcorn chicken.")
inputs = [''.join([f'{k}:{v}' for k, v in ling_atts.items()]) + prompt]
inputs = tokenizer(inputs, return_tensors='pt')
preds = model.generate(**inputs,
max_length=1024,
pad_token_id=tokenizer.pad_token_id,
no_repeat_ngram_size=2
)
decoded_preds = tokenizer.batch_decode(preds[:, inputs['input_ids'].shape[1]:],
skip_special_tokens=True)[0]
output = prompt + ' ' + decoded_preds.strip()
print(output)
```
## Citation
```BibTeX
@inproceedings{alhafni-etal-2024-personalized,
title = "Personalized Text Generation with Fine-Grained Linguistic Control",
author = "Alhafni, Bashar and
Kulkarni, Vivek and
Kumar, Dhurv and
Raheja, Vipul",
month = march,
year = "2024",
address = "Malta",
publisher = "Association for Computational Linguistics",
abstract = "As the text generation capabilities of large language models become increasingly prominent, recent studies have focused on controlling particular aspects of the generated text to make it more personalized. However, most research on controllable text generation focuses on controlling the content or modeling specific high-level/coarse-grained attributes that reflect authors’ writing styles, such as formality, domain, or sentiment. In this paper, we focus on controlling fine-grained attributes spanning multiple linguistic dimensions, such as lexical and syntactic attributes. We introduce a novel benchmark to train generative models and evaluate their ability to generate personalized text based on multiple fine-grained linguistic attributes. We systematically investigate the performance of various large language models on our benchmark and draw insights from the factors that impact their performance. We make our code, data, and pretrained models publicly available.",
}
``` |