Skip to content

Commit 545c1b3

Browse files
feat: making Granite 4 the default model (#178)
* Granite 4 is now default * Granite 4 is now default * Granite 4 notebbok updates
1 parent 6126bd9 commit 545c1b3

24 files changed

+63
-39
lines changed

docs/examples/best_of_n/prm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from docs.examples.helper import w
44
from mellea import start_session
5+
from mellea.backends.model_ids import IBM_GRANITE_3_3_8B
56
from mellea.backends.process_reward_models.huggingface.prms import (
67
HFGenerativePRM,
78
HFRegressionPRM,
@@ -11,7 +12,11 @@
1112
from mellea.stdlib.sampling.best_of_n import BestofNSamplingStrategy
1213

1314
# create a session for the generator using Granite 3.3 8B on Huggingface and a simple context [see below]
14-
m = start_session(backend_name="hf", model_options={ModelOption.MAX_NEW_TOKENS: 512})
15+
m = start_session(
16+
backend_name="hf",
17+
model_id=IBM_GRANITE_3_3_8B,
18+
model_options={ModelOption.MAX_NEW_TOKENS: 512},
19+
)
1520

1621
# initialize the PRM model
1722
prm_model = HFGenerativePRM(

docs/examples/generative_slots/generative_cot.py renamed to docs/examples/generative_slots/generative_gsm8k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ def extract_final_short_answer(
130130

131131
if __name__ == "__main__":
132132
scores = []
133+
m = start_session()
134+
133135
for question, target in (
134136
x.values() for x in load_dataset("gsm8k", "main", split="train[:100]")
135137
):
136-
m = start_session()
137-
138138
target = int(target.split("####")[-1])
139139
response = compute_chain_of_thought_and_final_answer(m, question=question)
140140
for step in response.step_by_step_solution:

docs/examples/generative_slots/generative_slots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def generate_summary(text: str) -> str:
1515

1616

1717
if __name__ == "__main__":
18-
with start_session():
19-
sentiment_component = classify_sentiment(text="I love this!")
18+
with start_session() as m:
19+
sentiment_component = classify_sentiment(m, text="I love this!")
2020
print("Output sentiment is : ", sentiment_component)
2121

2222
summary = generate_summary(

docs/examples/information_extraction/101_with_gen_slots.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from mellea import generative, start_session
44
from mellea.backends import model_ids
55

6-
m = start_session(model_id=model_ids.MISTRALAI_MISTRAL_0_3_7B)
6+
m = start_session()
77

88

99
@generative
1010
def extract_all_person_names(doc: str) -> list[str]:
11-
"""Given a document, extract all person names. Return these names as list of strings."""
11+
"""
12+
Given a document, extract names of ALL mentioned persons. Return these names as list of strings.
13+
"""
1214

1315

1416
# ref: https://www.nytimes.com/2012/05/20/world/world-leaders-at-us-meeting-urge-growth-not-austerity.html

docs/examples/information_extraction/advanced_with_m_instruct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def _at_least_(t: str) -> bool:
3535

3636

3737
# start session
38-
m = start_session(model_id=model_ids.MISTRALAI_MISTRAL_0_3_7B)
38+
m = start_session()
3939

4040
# run extraction using grounding context and sampling strategy
4141
sampled_p_names = m.instruct(
42-
"Extract the person names from the document (doc1).",
42+
"Extract ALL person names from the document (doc1).",
4343
grounding_context={"doc1": NYTimes_text},
4444
requirements=[check(None, validation_fn=simple_validate(at_least_n(2)))],
4545
strategy=RejectionSamplingStrategy(loop_budget=5),

docs/examples/instruct_validate_repair/101_email.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
# # start_session() is equivalent to:
1818
# from mellea.backends import model_ids
1919
# from mellea.backends.ollama import OllamaModelBackend
20-
# from mellea import MelleaSession, SimpleContext
20+
# from mellea import MelleaSession
21+
# from mellea.stdlib.base import SimpleContext
2122
# m = MelleaSession(
2223
# backend=OllamaModelBackend(
23-
# model_id=model_ids.IBM_GRANITE_3_3_8B,
24+
# model_id=model_ids.IBM_GRANITE_4_MICRO_3B,
2425
# model_options={ModelOption.MAX_NEW_TOKENS: 200},
2526
# ),
2627
# ctx=SimpleContext()

docs/examples/instruct_validate_repair/101_email_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"Write a very funny email to invite all interns to the office party."
1212
)
1313
print(
14-
f"***** email 1 ****\n{w(email_v1)}\n*******email 2 ******\n{w(email_v2)}\n*******"
14+
f"***** email 1 ****\n{w(email_v1)}\n*******email 2 ******\n{w(email_v2)}\n\n*******"
1515
)
1616

1717
# Use the emails as grounding context to evaluate which one is quirkier

docs/examples/instruct_validate_repair/101_email_with_requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# write an email with automatic requirement checking.
99
email_v1 = m.instruct(
1010
"Write an email to invite all interns to the office party.",
11-
requirements=["be formal", "Use 'Dear interns' as greeting."],
11+
requirements=["be formal", "Use 'Dear Interns' as greeting."],
1212
)
1313

1414
# print result

docs/examples/instruct_validate_repair/101_email_with_validate.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from docs.examples.helper import req_print, w
22
from mellea import start_session
3+
from mellea.backends.model_ids import IBM_GRANITE_3_3_8B
34
from mellea.backends.types import ModelOption
45
from mellea.stdlib.sampling import RejectionSamplingStrategy
56

6-
# create a session using Granite 3.3 8B on Ollama and a simple context [see below]
7+
# create a session using Granite 4 Micro (3B) on Ollama and a simple context [see below]
78
m = start_session(model_options={ModelOption.MAX_NEW_TOKENS: 200})
89

910
email_v2_samples = m.instruct(
10-
"Write an email to invite all interns to the office party.",
11-
requirements=["be formal", "Use 'Dear interns' as greeting."],
11+
"Write a very short email to invite all interns to the office party.",
12+
requirements=["Use formal language.", "Use 'Dear Interns' as greeting."],
1213
strategy=RejectionSamplingStrategy(loop_budget=3),
1314
return_sampling_results=True,
1415
)

docs/examples/mini_researcher/researcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@cache
2121
def get_session():
2222
"""Get M session (change model here)."""
23-
return MelleaSession(backend=OllamaModelBackend(model_ids.IBM_GRANITE_3_3_8B))
23+
return MelleaSession(backend=OllamaModelBackend(model_ids.IBM_GRANITE_4_MICRO_3B))
2424

2525

2626
@cache

0 commit comments

Comments
 (0)