How to change the "How to use from the Transformers library"

Hi,
I have uploaded my trained model to HF and created a model card for it.
I’m trying to modify the code snippet on the “How to use from the Transformers library” (after pressing the “use this model” top right button), how can I do that?

Thanks

Hi,

This can be done as shown in this PR: Add snippets to KerasNLP models by Wauplin · Pull Request #628 · huggingface/huggingface.js · GitHub. Basically there’s a file named “model-libraries-snippets.ts” (this is in TypeScript) where you can add your custom code snippet.

Is there a way that doesn’t involve changing the source code?

Pinging @osanseviero here

My main issue is that I want to have a snippet with different tokenizer from the model’s tokenizer, for both the pipeline and the direct use.
it supposed to look like that:

Unfortunately, you cannot directly modify the code snippet on the “How to use from the Transformers library” section of your uploaded model on Hugging Face. This code snippet is automatically generated based on the model you upload and the configuration files associated with it.

However, there are a few ways you can address this:

Update your Model Card:

The model card is the primary place for users to find information on how to use your model. You can clearly explain any specific steps or considerations needed when using your model in the “Usage” section of the model card. This includes mentioning any deviations from the standard Transformers library usage for your particular model.

Provide a Separate Usage Script:

You can upload a separate script or Jupyter Notebook to your model repository that demonstrates how to use your model. In the description of the script, mention that users should refer to this script for detailed usage instructions.

Link to an External Resource:

If you have a blog post, documentation, or another external resource that details how to use your model, you can link to that resource in the model card.

Here are some additional tips:

Be Clear and Concise: In your model card or external resource, provide clear and concise instructions on how to use your model. This should include information on:
    How to install any required dependencies
    How to load your model from the Hub
    How to prepare your data for inference
    How to make predictions with your model
Provide Examples: Including code examples in your model card or external resource can be incredibly helpful for users who want to quickly get started using your model.

These are all useful approaches, thank you!