Hugging Face is an online machine learning platform that allows users to create, share, and collaborate on machine learning models, datasets, and applications. We’ll need the access token from your account settings to access and upload models and datasets with Hugging Face. In this Answer, we’ll explain how to get the Hugging Face access token.
Open the browser and go to huggingface.co. We’ll see the following landing page of the platform. Click the “Sign Up” button in the top right corner:
We’ll see a form that requires our email and password, as shown in the screenshot below. Provide the information and click the “Next” button.
We’ll be redirected to a “Complete your profile” page. We have to choose our username and provide our full name. We can also link our X (formerly known as Twitter) and GitHub accounts here. Before proceeding, check the “Terms and Code of Conduct” check box.
Note: All the models and datasets you upload using Hugging Face will have your username. Be sure to choose a username to share with friends and family.
When we click the “Create Account” button, we’ll be asked to verify that we’re human. Select the correct options as the pop-up explains and click “Verify.”
Once we’ve verified that we are human, we’ll receive an email to verify the email address we provided. As shown in the screenshot below, we’ll be directed to our profile’s “Welcome” page. Click the “Resend confirmation email” button if you did not receive the email.
On the “Welcome” page, click your profile photo in the navigation bar and open the settings as shown below:
When we open settings, the profile settings will open by default, as shown in the screenshot below. Click the “Access Tokens” option in the sidebar.
On the “Access Tokens“ page, click the “New token” button as shown below:
A pop-up will appear when we click the “New token” button, as shown in the screenshot below. Provide a name and role for the token. The following role can be assigned to a token:
read
: The token will allow us to download models and datasets from Hugging Face.
write
: The token will allow us to download and upload models and datasets from Hugging Face.
Note: You must first confirm your email address to generate access tokens on Hugging Face.
Provide a name, select an appropriate role, and click the “Generate a token” button.
The token will now appear under “User Access Tokens” as shown below:
We can click the “Show” button to inspect the token value and press the copy button.
Keep your access token secure by removing it from your code before pushing it to GitHub.
We can now use this key to experience the awesomeness of Hugging Face!
In the following code, we will attempt to log in to the Huggingface_hub
using the access token you just generated.
Note: Replace
<ADD-YOUR-HUGGINGFACE-TOKEN-HERE>
with the value of your access token in the code.
from huggingface_hub import loginaccess_token = '<ADD-YOUR-HUGGINGFACE-TOKEN-HERE>'print(login(token = access_token))
Line 1: We import the login method from the huggingface_hub
library.
Line 3: We set the access token.
Line 4: We print the output of the login()
method when attempting to sign-in with the given access token.
Free Resources