|
from transformers import GPT2LMHeadModel, GPT2Tokenizer |
|
|
|
class TextToImageGenerator(torch.nn.Module): |
|
def __init__(self, model_name="gpt2"): |
|
super(TextToImageGenerator, self).__init__() |
|
self.tokenizer = GPT2Tokenizer.from_pretrained(model_name) |
|
self.gpt2 = GPT2LMHeadModel.from_pretrained(model_name) |
|
|
|
def forward(self, input_text): |
|
input_ids = self.tokenizer(input_text, return_tensors="pt")["input_ids"] |
|
output = self.gpt2(input_ids, return_dict=True) |
|
return output.logits |
|
|
|
|
|
model = TextToImageGenerator() |
|
|
|
|
|
print(model) |
|
|