Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added use auth token according to new hugging face #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LEAGUEDORA
Copy link

Since hugging face has updated their API, you cannot access Parrot models without using an auth token.
You may land into this issue

...is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'....

To solve this I added a new parameter called use_auth_token.

How to get a token from Huggingface

  1. Open Hugging Face and register/login with your credentials
  2. Nativate to Token settings page and create a write permitted access token.
  3. Copy the token and pass it as a parameter to Parrot class while initiating.

So the updated code will be

from parrot import Parrot
import torch
import warnings
warnings.filterwarnings("ignore")

''' 
uncomment to get reproducable paraphrase generations
def random_state(seed):
  torch.manual_seed(seed)
  if torch.cuda.is_available():
    torch.cuda.manual_seed_all(seed)

random_state(1234)
'''

#Init models (make sure you init ONLY once if you integrate this to your code)
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_auth_token = "<Your Hugging Face token>")

phrases = ["Can you recommend some upscale restaurants in Newyork?",
           "What are the famous places we should not miss in Russia?"
]

for phrase in phrases:
  print("-"*100)
  print("Input_phrase: ", phrase)
  print("-"*100)
  para_phrases = parrot.augment(input_phrase=phrase, use_gpu=False)
  for para_phrase in para_phrases:
   print(para_phrase)

@chriszhuada
Copy link

Hi there, any updates on when this PR will be merged? TY!

@LEAGUEDORA
Copy link
Author

Hi there, any updates on when this PR will be merged? TY!

No. I don't know when it is going to happen.

@PrithivirajDamodaran
Copy link
Owner

PrithivirajDamodaran commented Dec 1, 2022 via email

@chriszhuada
Copy link

In my code, I have

      self.parrot = Parrot(
            use_gpu=torch.cuda.is_available(),
        )

and I get the error

    self.parrot = Parrot(
  File "/usr/local/lib/python3.9/dist-packages/parrot/parrot.py", line 10, in __init__
    self.tokenizer = AutoTokenizer.from_pretrained(model_tag, use_auth_token=True)
  File "/usr/local/lib/python3.9/dist-packages/transformers/models/auto/tokenization_auto.py", line 560, in from_pretrained
    tokenizer_config = get_tokenizer_config(pretrained_model_name_or_path, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/transformers/models/auto/tokenization_auto.py", line 412, in get_tokenizer_config
    resolved_config_file = cached_file(
  File "/usr/local/lib/python3.9/dist-packages/transformers/utils/hub.py", line 409, in cached_file
    resolved_file = hf_hub_download(
  File "/usr/local/lib/python3.9/dist-packages/huggingface_hub/utils/_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/huggingface_hub/file_download.py", line 1054, in hf_hub_download
    headers = build_hf_headers(
  File "/usr/local/lib/python3.9/dist-packages/huggingface_hub/utils/_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/huggingface_hub/utils/_headers.py", line 117, in build_hf_headers
    token_to_send = get_token_to_send(token)
  File "/usr/local/lib/python3.9/dist-packages/huggingface_hub/utils/_headers.py", line 149, in get_token_to_send
    raise EnvironmentError(
OSError: Token is required (`token=True`), but no token found. You need to provide a token or be logged in to Hugging Face with `huggingface-cli login` or `huggingface_hub.login`. See https://huggingface.co/settings/tokens.

@chriszhuada
Copy link

Not sure if it matters, but I'm using a poetry project for my project:

parrot = { git = "https://github.com/PrithivirajDamodaran/Parrot_Paraphraser.git", branch = "main" }

@chriszhuada
Copy link

Was able to get it work by

from huggingface_hub import login

login(token=HUGGINGFACE_TOKEN)

in my file that imports Parrot!

@ucas010
Copy link

ucas010 commented Dec 27, 2022

NameError: name 'HUGGINGFACE_TOKEN' is not defined

@LEAGUEDORA
Copy link
Author

NameError: name 'HUGGINGFACE_TOKEN' is not defined

Define a constant with like

HUGGINGFACE_TOKEN = 'YOUR_TOKEN'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants