0
0
Prompt Engineering / GenAIml~10 mins

Self-hosted LLMs (Llama, Mistral) in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a self-hosted Llama model using the Hugging Face Transformers library.

Prompt Engineering / GenAI
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained('[1]')
Drag options to blanks, or click blank then click option'
Allama-2-7b
Bgpt-3
Cbert-base-uncased
Dmistral-7b
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPT or BERT model names instead of Llama.
2fill in blank
medium

Complete the code to generate text from a loaded Mistral model using the generate method.

Prompt Engineering / GenAI
outputs = model.generate(input_ids, max_length=[1])
Drag options to blanks, or click blank then click option'
Atokenizer
Binput_ids
Cmodel
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variables like input_ids or tokenizer instead of an integer.
3fill in blank
hard

Fix the error in the code to correctly tokenize input text for a self-hosted Llama model.

Prompt Engineering / GenAI
inputs = tokenizer('[1]', return_tensors='pt')
Drag options to blanks, or click blank then click option'
Atokenizer
Bmodel
CHello, how are you?
Dgenerate
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variable names or method names as strings instead of actual text.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.

Prompt Engineering / GenAI
{word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value or wrong comparison operators.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of uppercase words and their lengths for words longer than 4 characters.

Prompt Engineering / GenAI
{ [1]: [2] for [3] in words if len([3]) > 4 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Cword
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently or wrong functions.