Chapter 2 questions

Probably a little pitfall:

Hello, I believe there is a little pitfall in the instruction of “Behind the pipeline”, looks as the following:

Negative score should be “0.11%”, instead of “0.,11%”. This might cause some confusing.

2973622476

"The problem is that we sent a single sequence to the model, whereas :hugs: Transformers models expect multiple sentences by default. " - this does not seem to be a problem with Tensorflow code. Tensorflow accepts single sequence also without need for batch dimension unlike PyTorch which requires the sequence to be given with additional batch dimension

same here!
in fact without adding special tokens , I’ve got better results outputted from SoftMax function.

Hi Sylvain
First of all, thanks a tonne for this detailed course! :pray:
A bit confused why I am not getting this error?

1 Like

What is the difference between AutoTokenizer and BertTokenizer

Hello Sylvain, I am just wondering if there’s a comprehensive list of tasks/pipelines anywhere? I thought it might be here Tasks - Hugging Face , but in the tutorial for this page, it mentions the “sentiment-analysis” task, which is not available on that link.

1 Like

How do I know which tokenizer to choose?
Example 1.
"The dog’s ran into the church. "
model 1: [ The, dog’s, ran, into, the, church]

model 2: [ The, dog, 's, ran, into, the, church]

This provides 2 different meaning to a model. How do I know to choose a tokenizer that store the whole word or breaks down the parts of a word?

I don’t know why this error appear.

Both are quite the same with the only difference being that bert tokenizer is specifically focused for the bert ecosystem and It handles special tokens like [CLS] (classification token), [SEP] (separator token), and [MASK] (mask token) that are specific to BERT.
Whereas the auto tokenizer is more general and versatile and can be used for multiple other models

Lesson : Behind the pipeline.

The lesson mentions the term “head” in the transformer architecture. Is it talking about attention heads ? Something is not clear to me. Is it an encoder only model ? What are the hidden states in the transformer architecture ?

Could you please help me to understand, do Tokenization and Embeddings both required to use Transformers?
In inferencing due we need to perform Tokenization / Embedding before passing the input ?

Simple question

I’m a beginner in using HF library.

Why does Hugging face define the AutoModel class and insist users to use the AutoModelForSequenceClassification instead ?

Hi, for calling the model with the tokens tensor, why do you pass **tokens not only tokens

tokens = tokenizer(sequences, padding=True, truncation=True, return_tensors=“tf”)
output = model(**tokens)

I found this answer from Google Gemini
The double star (**) in a function call is used to unpack a dictionary into keyword arguments.

For example, if you have a dictionary my_dict = {'a': 1, 'b': 2}, calling my_function(**my_dict) is equivalent to calling my_function(a=1, b=2).

Hugging Face model expects to receive two keyword arguments (input_ids & attention_mask) & hence unpacking is necessary

Wondering if/how padding would lead to the same logits for longer sequences if we have to worry about positional encodings. It seems to me that the positional encoding added to non-pad tokens would be different than if you had no pad tokens to begin with?

Hey!
Thank you for great course. Can you please explain how it happens that agent by calling suggest_menu function which just returns string : “Custom menu for the butler.” is receiving result with detailed list of food?

formal_menu = {                                                                                                  
      "Appetizers": [                                                                                              
          "Cucumber and Cream Cheese Canapés",                                                                     
          "Smoked Salmon and Avocado Bruschetta",                                                                  
          "Mini Quiches with Mushroom and Spinach Filling"                                                         
      ],                                                                                                           
      "Main Courses": [                                                                                            
          "Grilled Rack of Lamb with Roasted Vegetables",                                                          
          "Seared Sea Bass with Lemon Butter Sauce",                                                               
          "Classic Beef Wellington"                                                                                
      ],                                                                                                           
      "Desserts": [                                                                                                
          "Chocolate Lava Cake with Vanilla Ice Cream",                                                            
          "Carrot Cake with Cream Cheese Frosting",                                                                
          "Fresh Berries with Mascarpone Cheese"                                                                   
      ]                                                                                                            
  }                                                                                                                
                                                                                                                   
  print("Formal Party Menu.")                                                                                      
  for category, dishes in formal_menu.items():                                                                     
      print(f"\n{category}:")                                                                                      
      for dish in dishes:                                                                                          
          print(f"- {dish}")        

I mean this snippet

```python 
agent = CodeAgent(tools=[suggest_menu], model=HfApiModel())
How this part works?
Thanks.

P.S. It even finds similar answer without using `suggest_menu` tool. So second question why is this tool needed?

final_menu = “”"
---- Menu ----

Appetizers:

  • Bruschetta with Fresh Tomatoes and Basil: Grilled bread topped with diced tomatoes, fresh basil, garlic, and
    a drizzle of olive oil.
  • Asparagus Spears with Hollandaise Sauce: Thinly sliced asparagus cooked until tender, lightly topped with
    hollandaise sauce.
  • Savory Mini Meatballs: Small meatballs made with a blend of ground beef, pork, and veal, served with a
    decadent marinara sauce.

Main Courses:

  • Pan-Seared Salmon with Dill Cream Sauce: Fresh salmon, pan-seared to perfection, served atop a creamy sauce
    infused with fresh dill.
  • Filet Mignon with Truffle Butter: A succulent 8-ounce filet mignon, cooked to your liking, brushing with a
    rich truffle butter.
  • Roast Chicken with Rosemary and Lemon: Juicy whole chicken seasoned with rosemary and lemon herbs, roasted to
    golden perfection.

Side Dishes:

  • Creamy Mashed Potatoes
  • Roasted Brussels Sprouts
  • Garlic Mashed Cauliflower

Desserts:

  • Chocolate Lava Cake
  • Vanilla Bean Panna Cotta
  • Fresh Fruit Platter

Drinks:

  • Sparkling Wine
  • Chilled White Wine
  • Rich Red Wine
  • Signature Cocktail
  • Soft Drinks
    “”"

Providing the final answer

final_answer(final_menu)

1 Like

Hey @sgugger ,
When I try to interact with the Alfred Agent i pushed to the Hub, I get:

Where do I put the username/password?

1 Like

After pushing the agent to hub , I am not able to run the agent as it is showing incorrect password.Also in the subcourse( Building Agents That Use Code) while using the agent (AlfredAgent)made by huggingface it is showing error.

For the Smolagents course, unit 2.1, multi-agents system, the google collab notebook could be improved.
For example in the check_reasoning_and_plot function, I do not understand why we need to use OpenAi gpt4o?

It could simply be:

def check_reasoning_and_plot(final_answer, agent_memory):
    final_answer
    multimodal_model = HfApiModel("Qwen/Qwen2.5-Coder-32B-Instruct", provider="together", max_tokens=8096)
1 Like
  1. consider this:
    If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
    model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'

  2. also try set your HF_TOKEN in the Secrets of your Colab

1 Like