abertsch72 / perspective-shifting

Code for the Findings of EMNLP 2022 paper "He Said, She Said: Style Transfer for Shifting the Perspective of Dialogues"
6 stars 0 forks source link

Any guide on inference #1

Open Ricardokevins opened 1 year ago

Ricardokevins commented 1 year ago

Hi Thank you for sharing your awesome work~

Can you provide further guide on using your model as API for Shifting the Perspective of Dialogues?

abertsch72 commented 1 year ago

Thanks for your interest in the work!

We're still checking whether we're able to release model weights (the data has a licensing restriction that makes this a bit nontrival). If/when we release the model weights, it will be as a HuggingFace model-- so you can do generation exactly as the HuggingFace documentation suggests.

We recommend the "line-to-line" setup, where the full dialogue is provided as input and perspective shifted one line at a time.

In this setup, if your dialogue was the following:

Sam: hey i'll be late today! John: no worries lol Sam: see u soon

You'd make three calls to the model, putting <SEP> tokens around each utterance in turn. The first of these calls would look something like this:

input_ids = tokenizer("<SEP>Sam: hey i'll be late today!<SEP>\nJohn: no worries lol\nSam: see u soon").input_ids
outputs = model.generate(input_ids, max_length=30)
ps1 = tokenizer.decode(outputs, skip_special_tokens=True) #output: Sam says he will be late today. 

Of course, you can batch this to make it a bit faster :)

We also discuss a conversation-level perspective shift in the paper, which only requires one call to the model for each conversation. If you were using the conversation-level model, the call would look like this:

input_ids = tokenizer("Sam: hey i'll be late today!\nJohn: no worries lol\nSam: see u soon").input_ids
outputs = conversation_model.generate(input_ids, max_length=30)
ps_full = tokenizer.decode(outputs, skip_special_tokens=True) #output: Sam says he will be late today.\nJohn laughs and says no worries.\nSam says he will see John soon.

I do apologize that the weights aren't available yet-- I'll comment on this issue again when we make a final decision on the release, likely in January. Thanks!

Ricardokevins commented 1 year ago

Thank you for your reply. Looking forward to using your interesing model and learing your paper as soon~