Comments (5)
Hello @kaiisongit
Did you manage to find a solution to this issue? I am facing the same problem.
It would be great if you could share it.
Regards,
Paritosh
from lm-scorer.
Hi, I didn't find a solution, but I managed to scramble together this code which does what I need - score is a function that when you pass it a sentence as a string, gives you the loss. Lower numbers are better.
import math
import torch
from pytorch_pretrained_bert import OpenAIGPTTokenizer, OpenAIGPTModel, OpenAIGPTLMHeadModel
model = OpenAIGPTLMHeadModel.from_pretrained('openai-gpt')
model.eval()
model.to('cuda')
tokenizer = OpenAIGPTTokenizer.from_pretrained('openai-gpt')
def score(sentence):
tokenize_input = tokenizer.tokenize(sentence)
indexed_tokens = tokenizer.convert_tokens_to_ids(tokenize_input)
tokens_tensor = torch.tensor([indexed_tokens])
tokens_tensor = tokens_tensor.to('cuda')
loss=model(tokens_tensor, lm_labels=tokens_tensor)
return math.exp(loss)
from lm-scorer.
if you aren't using cuda, you can remove the two lines: model.to('cuda') and tokens_tensor = tokens_tensor.to('cuda')
from lm-scorer.
Hello @kaiisongit,
Thanks for sharing your code.
However, I am working on the transformers-based model, and I started getting the same errors during deployment. Hence, I was looking for a solution.
Anyways, thanks for the prompt reply.
from lm-scorer.
I'm getting a similar error:
ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py in _get_module(self, module_name)
10 frames
ModuleNotFoundError: No module named 'transformers.models.gpt2.modeling_gpt2'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py in _get_module(self, module_name)
RuntimeError: Failed to import transformers.models.gpt2.modeling_gpt2 because of the following error (look up to see its traceback):
No module named 'transformers.models.gpt2.modeling_gpt2'
Was a solution provided?
from lm-scorer.
Related Issues (11)
- Unable to run lm-scorer HOT 1
- Python 3.8 support? HOT 5
- Not really correct to include <|endoftext|> token in scoring?
- Support for AutoModelWithLMHead
- Support for Python 3.8
- ValueError: Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' 'truncation=True' to have batched tensors with the same length. Perhaps your features (`input_ids` in this case) have excessive nesting (inputs type `list` where type `int` is expected).
- Possible missing words HOT 1
- Couple of queries: 1) Fine tuned GPT2 2) BPE Encoding HOT 2
- AH01215: OSError: Couldn't reach server at 'https://s3.amazonaws.com/models.huggingface.co/bert/gpt2-config.json' to download pretrained model configuration file HOT 6
- couldn't load pretrained gpt2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lm-scorer.