Coder Social home page Coder Social logo

Can't load config for 'gpt2' about lm-scorer HOT 5 OPEN

simonepri avatar simonepri commented on July 21, 2024
Can't load config for 'gpt2'

from lm-scorer.

Comments (5)

katreparitosh avatar katreparitosh commented on July 21, 2024

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.

kaiisongit avatar kaiisongit commented on July 21, 2024

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.

kaiisongit avatar kaiisongit commented on July 21, 2024

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.

katreparitosh avatar katreparitosh commented on July 21, 2024

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.

caroarriaga avatar caroarriaga commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.