Views
No views yet
1from transformers import AutoModel, AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained("rrivera1849/LUAR-MUD")
4model = AutoModel.from_pretrained("rrivera1849/LUAR-MUD")
5
6# we embed `episodes`, a colletion of documents presumed to come from an author
7# NOTE: make sure that `episode_length` consistent across `episode`
8batch_size = 3
9episode_length = 16
10text = [
11 ["Foo"] * episode_length,
12 ["Bar"] * episode_length,
13 ["Zoo"] * episode_length,
14]
15text = [j for i in text for j in i]
16tokenized_text = tokenizer(
17 text,
18 max_length=32,
19 padding="max_length",
20 truncation=True,
21 return_tensors="pt"
22)
23# inputs size: (batch_size, episode_length, max_token_length)
24tokenized_text["input_ids"] = tokenized_text["input_ids"].reshape(batch_size, episode_length, -1)
25tokenized_text["attention_mask"] = tokenized_text["attention_mask"].reshape(batch_size, episode_length, -1)
26print(tokenized_text["input_ids"].size()) # torch.Size([3, 16, 32])
27print(tokenized_text["attention_mask"].size()) # torch.Size([3, 16, 32])
28
29out = model(**tokenized_text)
30print(out.size()) # torch.Size([3, 512])
31
32# to get the Transformer attentions:
33out, attentions = model(**tokenized_text, output_attentions=True)
34print(attentions[0].size()) # torch.Size([48, 12, 32, 32])@inproceedings{uar-emnlp2021,
author = {Rafael A. Rivera Soto and Olivia Miano and Juanita Ordonez and Barry Chen and Aleem Khan and Marcus Bishop and Nicholas Andrews},
title = {Learning Universal Authorship Representations},
booktitle = {EMNLP},
year = {2021},
}