I want help to debug my colab notebook script
- User
I want help to debug my colab notebook script
- Assistant
Sure, I can help you debug your Colab notebook script. Please either:
Paste the relevant code snippet here, and let me know what issue you're facing (error message, unexpected behavior, etc.), or
Upload the notebook file (.ipynb) directly so I can take a look at the whole thing.
Let me know what you'd prefer!
- User
Load the model and tokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained("dicta-il/dictalm2.0-instruct", torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32, device_map="auto") tokenizer = AutoTokenizer.from_pretrained("dicta-il/dictalm2.0-instruct")
from google.colab import drive drive.mount('/content/drive')
SEED = 31 OUTPUT_LEN = 2048 N = 1
Load your CSV
input_csv = "/content/drive/MyDrive/Kamin/data/merged_turns_by_discussion_2025-07-07.csv" # upload to Colab output_csv = "/content/drive/MyDrive/Kamin/data/parsed_output.csv"
df = pd.read_csv(input_csv) df["split"] = "test" df.loc[df.sample(n=N, random_state=SEED).index, "split"] = "dev" df = df[df["split"] == "dev"] # optional: filter to dev only
Initialize parsed DataFrame
parsed_df = pd.DataFrame(columns=["Discussion", "Title", "Theme", "DU_id", "eTU_id", "eTU_type", "Text", "Turn", "Author", "split"]) PARSING_TURN = """You are a Hebrew linguistic specialist. You will analyze a dialogue between multiple speakers and extract structured data. Instead of dealing with the full dialogue at once, I will show you a single turn at a time.
Instructions:
- Identify the key theme(s) of the turn.
- Segment the turn into Discourse Units (DUs) and Elementary Turn Units (eTUs).
- Number the DUs, starting from 1.
- Number the eTUs, starting from 1, within each DU.
- Label each eTU as one of: “Claim”, “Question” or “Meta”.
Output Format (JSON)
{ "themes": ["theme1", "theme2", ...], "Turn": [ { "Text": "string", “eTU_id”: number "eTU_type": "Claim | Question | Meta", “DU_id”: number, "Theme": "string" } … ] }
Definitions
Discourse Unit (DU): A single communicative act of a turn. If a turn contains multiple claims, each introducing a new aspect, example, or detail, each should be a separate DU.
Elementary Turn Unit (eTU): The eTU is the smallest unit within a DU.
Segmentation Guidelines
- If a sentence or clause introduces a new aspect, example, or detail, it should be split into a new DU (and thus a new eTU).
- Closely related questions within the same topic may be kept in one eTU.
- Expressions of agreement/disagreement (e.g., "אני מסכימה", "נכון") should be treated as a separate DU if followed by an additional communicative act.
Example:
- "האם הדעה שלך זהה גם על המצב אז? מה ההבדל?" → One eTU, type: Question.
-
If a turn contains an agreement/disagreement marker (such as "אני מסכימה", "נכון", "לא נכון", etc.) followed by a separate claim, explanation, or other communicative act:
- The agreement/disagreement marker should be its own DU/eTU (type: Claim).
- The claim, explanation, or reasoning should be a separate DU/eTU (type: Claim).
-
Split claims when a general/contextual statement is followed by a specific example, evidence, or reference to a source. For example, if a speaker first makes a general claim and then immediately supports it with a reference to a text, historical fact, or explicit example, treat each as a separate eTU, even if they are both claims.
-
When in doubt, if a sentence introduces a new aspect, evidence, or reference, consider starting a new eTU.
Example: "בתקופה אז , שעוד לא הייתה מדינה באופן רשמי והעם היהודי רק התחיל להתארגן במושבות ובמוסדות חינוכיים , הייתה חשיבות גדולה לשימוש בשפה העברית ." → eTU 1, eTU_type: Claim "אפשר לראות מהמקור כמה היה חשוב אז לבסס את השפה כשולטת בארץ ." → eTU 2, eTU_type: Claim
- When a DU contains a claim (statement, contextualization, or assertion) immediately followed by a question (or vice versa), split them into separate eTUs, even if they are closely related or about the same topic.
- Do not combine claims and questions in the same eTU, even if they are in the same sentence or closely related. Always split when the communicative act type changes.
Example:
-
"הדיון שלנו כפול בכך שהמצב שונה היום ובתקופת מלחמת השפות , האם הדעה שלך זהה גם על המצב אז ? מה ההבדל ?" eTU 1: "הדיון שלנו כפול בכך שהמצב שונה היום ובתקופת מלחמת השפות ," → eTU_type: Claim eTU 2: "האם הדעה שלך זהה גם על המצב אז ? מה ההבדל ?" → eTU_type: Question
-
When a turn begins with a discourse marker, conversational opener, or hedge (e.g., "טוב", "אז", "בעצם", "תראה", "האמת", "לדעתי", "נראה לי", etc.), treat it as a separate eTU if it stands alone or is separable from the main communicative act. Example: "טוב , זה נראה לי כבר עניין של ערכים" DU 1: "טוב ," → eTU_type: Claim DU 2: "זה נראה לי כבר עניין של ערכים" → eTU_type: Claim
-
If the marker is tightly integrated into the following statement and cannot be separated without loss of meaning, keep it within the same eTU.
-
Before finalizing your segmentation and labeling of any turn, check whether the turn is similar in structure or content to any of the examples provided in the guidelines. If it is:
-
Apply the same segmentation logic and eTU types as shown in the matching example.
-
If the structure is identical but you segmented or labeled it differently, revise your output to match the example pattern.
-
If the turn is only partially similar, explain your reasoning for any differences in segmentation or labeling.
Examples
Turn: “היי חברים , צהריים טובים : ) עלינו לדון במהי הסיבה המרכזית שמובילה לסייבר בולינג , מצרפת לנו הגדרה שמצאתי באינטרנט בכדי שנבין כיצד יותר מזה בכלל סייבר בולינג : בריונות ברשת היא התנהגות פוגענית , שמבצעיה משתמשים באמצעים טכנולוגיים כמו האינטרנט או הטלפון הנייד על מנת להשמיץ , להטריד , להביך , להפחיד או לתקוף מישהו . בריונות מקוונת יכולה להתרחש בכל אחת מהמדיות הדיגיטליות , פייסבוק , וואטס-אפ , טוויטר בלוגים , צ'טים , פורומים , דואר אלקטרוני , אתרי אינטרנט ועוד . היא יכולה להיות מילולית , והיא יכולה להתבטא גם בפרסום של תמונות או סרטונים . לפי דעתי , הסיבה המובילה להתנהגות מסוג זה היא הההתחבאות מאחורי הטכנולוגיה הזו שמשרה ביטחון על אותו ילד שלא מודע באופן ישיר לכך שהוא פוגע בבנאדם ולא באמת מסתכל לו בעיניים , אלא מתחבא מאחורי המחשב או הפלאפון . זוהי לא הסיבה העיקרית המובילה לכך , אך לפי דעתי זוהי סיבה שאנשים פוגעים בלי להיות מודעים לרמת הפגיעה .”
{ "themes": ["theme1", "theme2", ...], "Turn": [ { "Text": “היי חברים , צהריים טובים : )”, “eTU_id”: 1 "eTU_type": "Meta", “DU_id”: 1, "Theme": "פתיחה" }, { "Text": “עלינו לדון במהי הסיבה המרכזית שמובילה לסייבר בולינג ,”, “eTU_id”: 1 "eTU_type": "Meta", “DU_id”: 2, "Theme": "פתיחה" }, { "Text": “מצרפת לנו הגדרה שמצאתי באינטרנט בכדי שנבין כיצד יותר מזה בכלל סייבר בולינג : בריונות ברשת היא התנהגות פוגענית , שמבצעיה משתמשים באמצעים טכנולוגיים כמו האינטרנט או הטלפון הנייד על מנת להשמיץ , להטריד , להביך , להפחיד או לתקוף מישהו .”, “eTU_id”: 2 "eTU_type": "Claim", “DU_id”: 2, "Theme": "-" }, { "Text": “בריונות מקוונת יכולה להתרחש בכל אחת מהמדיות הדיגיטליות , פייסבוק , וואטס-אפ , טוויטר בלוגים , צ'טים , פורומים , דואר אלקטרוני , אתרי אינטרנט ועוד .”, “eTU_id”: 3 "eTU_type": "Claim", “DU_id”: 2, "Theme": "-" }, { "Text": “היא יכולה להיות מילולית ,”, “eTU_id”: 4 "eTU_type": "Meta", “DU_id”: 2, "Theme": "-" }, { "Text": “והיא יכולה להתבטא גם בפרסום של תמונות או סרטונים .”, “eTU_id”: 5 "eTU_type": "Claim", “DU_id”: 2, "Theme": "-" }, { "Text": “לפי דעתי , הסיבה המובילה להתנהגות מסוג זה היא הההתחבאות מאחורי הטכנולוגיה הזו שמשרה ביטחון על אותו ילד שלא מודע באופן ישיר לכך שהוא פוגע בבנאדם ולא באמת מסתכל לו בעיניים , אלא מתחבא מאחורי המחשב או הפלאפון .”, “eTU_id”: 1 "eTU_type": "Claim", “DU_id”: 3, "Theme": "-" }, { "Text": “זוהי לא הסיבה העיקרית המובילה לכך ,”, “eTU_id”: 2 "eTU_type": "Claim", “DU_id”: 3, "Theme": "-" }, { "Text": “אך לפי דעתי זוהי סיבה שאנשים פוגעים בלי להיות מודעים לרמת הפגיעה .”, “eTU_id”: 3 "eTU_type": "Claim", “DU_id”: 3, "Theme": "-" } ] }
Turn: "שלום, מה הדעות שלכם? אני בעד שימוש בשפה מייצגת כיוון שיש לה יתרונות רבים כמו תקשורת עם שאר העולם בתחומים רבים כמו לימודים." { "themes": ["בעד השימוש בשפה מייצגת”], "Turn": [ { "Text": "שלום, מה הדעות שלכם?", “eTU_id”: 1 "eTU_type": "Question", “DU_id”: 1, "Theme": "פתיחה" }, { "Text": "אני בעד שימוש בשפה מייצגת...", “eTU_id”: 1 "eTU_type": "Claim", “DU_id”: 1, "Theme": "בעד שפה מייצגת" } ] } """
Inference loop using HuggingFace model
for index, row in tqdm(df.iterrows(), total=len(df)): discussion = row['Discussion'] sample = row['Formatted'] turn = row["Turn"] author = row["Author"]
# Create chat format for the Dicta model combined_prompt = f"{PARSING_TURN.strip()}\n\n**Turn**:{sample}" messages = [ {"role": "user", "content": combined_prompt} ] try: encoded = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device) generated_ids = model.generate(encoded, max_new_tokens=OUTPUT_LEN, do_sample=False) decoded = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] df.at[index, 'llm_output'] = decoded # Try to parse JSON from model's output parsed_data = json.loads(decoded) res_themes = parsed_data.get("themes", "") new_rows = [] for item in parsed_data.get("Turn", []): new_rows.append({ "Turn": turn, "Theme": item.get("Theme", ""), "eTU_id": item.get("eTU_id", ""), "DU_id": item.get("DU_id", ""), "eTU_type": item.get("eTU_type", ""), "Text": item.get("Text", ""), "Author": author, "split": df.at[index, "split"] }) parsed_df = pd.concat([parsed_df, pd.DataFrame(new_rows)]) parsed_df.to_csv(output_csv) except json.JSONDecodeError as e: print(f"[ERROR] JSON parsing failed for discussion {discussion}: {e}") df.at[index, 'llm_output'] = f"[ERROR] JSON parse error: {e}" except Exception as e: print(f"[ERROR] Failed processing discussion {discussion}: {e}") df.at[index, 'llm_output'] = f"[ERROR] LLM failure: {e}"Save results
df.to_csv(output_csv.replace(".csv", "_with_raw_output.csv")) parsed_df.to_csv(output_csv)
- Assistant
Thanks for sharing your Colab notebook script! It looks very well structured and clear. To help debug it properly, I need to know: ❓ What’s the actual issue you're facing?
Are you getting a specific error message?
Is there
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.