Text Generation
Transformers
PyTorch
English
Inference Endpoints
timonziegenbein commited on
Commit
66f88bd
·
verified ·
1 Parent(s): 318b471

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -1
README.md CHANGED
@@ -9,4 +9,80 @@ metrics:
9
  - perplexity
10
  library_name: transformers
11
  pipeline_tag: text-generation
12
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  - perplexity
10
  library_name: transformers
11
  pipeline_tag: text-generation
12
+ ---
13
+
14
+ # Model Card for appropriateness-rewriter
15
+
16
+ <!-- Provide a quick summary of what the model is/does. -->
17
+
18
+ This model rewrites inappropriate arguments to become more appropriate. For further details on (in)appropriateness, we refer to the paper below and the corpora used for training.
19
+
20
+ There are four different versions of this model with different balancing of appropriateness and semantic similarity (ordered by appropriateness below):
21
+ - timonziegenbein/appropriateness-rewriter
22
+ - timonziegenbein/appropriateness-rewriter-app-gt-sim
23
+ - timonziegenbein/appropriateness-rewriter-app-eq-sim
24
+ - timonziegenbein/appropriateness-rewriter-sim-gt-app
25
+
26
+
27
+ NOTE: This repository contains only the adapter for the trained alpaca model (see [here](https://huggingface.co/timonziegenbein/alpaca-7b)).
28
+
29
+ ## Model Details
30
+
31
+ ### Model Sources
32
+
33
+ <!-- Provide the basic links for the model. -->
34
+
35
+ - **Repository:** [https://github.com/timonziegenbein/inappropriateness-mitigation]
36
+ - **Paper [optional]:** [LLM-based Rewriting of Inappropriate Argumentation using Reinforcement Learning from Machine Feedback
37
+ ](https://arxiv.org/abs/2406.03363)
38
+
39
+
40
+ ## How to Get Started with the Model
41
+
42
+ Use the code below to get started with the model.
43
+
44
+ ```
45
+ from transformers import AutoModelForCausalLM, AutoTokenizer
46
+ from transformers import pipeline
47
+ from peft import PeftModel, PeftConfig
48
+
49
+ GEN_ARGS = {
50
+ "do_sample": True,
51
+ "top_p": 0.95,
52
+ "top_k": 0,
53
+ "max_new_tokens": 2048,
54
+ "temperature": 1.0,
55
+ }
56
+
57
+
58
+ INSTRUCT_PRE = '''Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n'''
59
+ INSTRUCT_PATTERN = '''### Instruction:\nRewrite the following argument to be more appropriate and make only minimal changes to the original argument.\n\n### Input:\n{}\n\n### Response:\n'''
60
+
61
+ tokenizer = AutoTokenizer.from_pretrained("timonziegenbein/alpaca-7b")
62
+ peft_config = PeftConfig.from_pretrained('timonziegenbein/appropriateness-app-gt-sim')
63
+ model = AutoModelForCausalLM.from_pretrained(peft_config.base_model_name_or_path)
64
+ peft_model = PeftModel.from_pretrained(model, 'timonziegenbein/appropriateness-app-gt-sim').to('cuda')
65
+
66
+ argument = ''''Towed three times and impounded for 30 days each time? Man, you're just not getting the message, are you? If you are in California, you bet the police can forfeit your vehicle and it doesn't take three times to make it a charm. Technically, your vehicle could be subject to forfeiture proceedings after your first suspended license beef. Someone like you is exactly the reason the legislature designed that law, because your privilege to drive has been taken away from you and yet you obviously continue to drive. People like you are involved in an exponentially higher than average number of traffic accidents so the legislature figured maybe people like you should have your vehicles forfeited to the state if you just didn't go along with the game plan. Voila - I give you California Vehicle Code section 14607.6...and a link to it below. It would also be worth your time to review 14607.4, whether or not you live in California. You really need to stop driving. Really.'''
67
+
68
+ prompt = INSTRUCT_PRE + INSTRUCT_PATTERN.format(argument)
69
+ prompt_input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")
70
+ outputs = peft_model.generate(
71
+ input_ids=prompt_input_ids,
72
+ **GEN_ARGS,
73
+ )
74
+
75
+ decoded_outputs = []
76
+ for output in outputs:
77
+ decoded_outputs.append(tokenizer.decode(output[len(prompt_input_ids[0]):], skip_special_tokens = True).strip())
78
+
79
+ print(decoded_outputs)
80
+ ```
81
+
82
+ ## Citation
83
+
84
+ <!-- If there is a paper or blog post introducing the dataset, the APA and Bibtex information for that should go in this section. -->
85
+
86
+ If you are interested in using this model, please cite the following papers:
87
+ [Modeling Appropriate Language in Argumentation](https://aclanthology.org/2023.acl-long.238) (Ziegenbein et al., ACL 2023)
88
+ [LLM-based Rewriting of Inappropriate Argumentation using Reinforcement Learning from Machine Feedback](https://arxiv.org/abs/2406.03363) (Ziegenbein et al., ACL 2024)