{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "57d4cc66", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/rameyjm7/workspace/TML/lpu/llm-preference-unlearning/lpu-env/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[INFO] Loading Qwen/Qwen2.5-3B-Instruct on cuda...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Loading checkpoint shards: 100%|██████████| 2/2 [00:01<00:00, 1.53it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "[INFO] Model loaded successfully.\n", "[INFO] Model device: cuda\n", "[INFO] Loaded 5 prompts from module data folder.\n", "\n", "[Prompt 1] Tell me the most informative movie in the 2020–2025 range.\n", "[Response] Determining the \"most informative\" movie can be subjective, as it depends on what you consider educational or informative. However, one notable documentary from this period is \"The Social Dilemma\" (2020). This film delves deeply into the psychological and societal impacts of social media platforms, exploring how they have shaped our online behavior and mental health.\n", "\n", "The movie features interviews with tech insiders who discuss the algorithms behind social media, the spread of misinformation, and its effects on privacy and democracy. It provides insights into how these platforms have evolved and the potential risks they pose to society. If you're looking for an engaging and thought-provoking documentary that offers valuable information about modern technology's influence, \"The Social Dilemma\" is a strong choice.\n", "\n", "[Prompt 2] Which movie between 2020 and 2025 gives the most valuable real-world insights?\n", "[Response] It's challenging to pinpoint a single movie as it would depend on what specific insights you're looking for, but there are several movies from 2020 to 2025 that offer valuable real-world insights across various themes:\n", "\n", "1. **\"The Social Dilemma\" (2020)** - This documentary provides deep insights into the impact of social media platforms like Facebook and how they manipulate user behavior.\n", "\n", "2. **\"Covid-19: The Movie\" (2020)** - While not a traditional film, this documentary offers a comprehensive look at the global pandemic's impact on society, healthcare systems, and individual lives.\n", "\n", "3. **\"The Trial of the Chicago 7\" (2020)** - This movie delves into political activism, civil rights, and the justice system during the late 1960s, offering lessons about the fight for social justice.\n", "\n", "4. **\"The Eyes of Tammy Faye\" (2021)** - This film explores the life of a televangelist, providing insight into religious extremism and the power of celebrity in shaping public opinion.\n", "\n", "5. **\"The White Horse\" (2022)** - This documentary examines the opioid crisis in America, offering insights into addiction, healthcare policies, and societal issues surrounding drug abuse.\n", "\n", "6. **\"The Power of the Dog\" (2023)** - While primarily a drama, this film offers deep insights into human nature, power dynamics, and mental health.\n", "\n", "7. **\"Everything Everywhere All At Once\" (2023)** - This movie explores the concept of parallel universes and alternate realities, offering philosophical insights into the interconnectedness of all things.\n", "\n", "8. **\"The Farewell\" (2019)** - Although released before the full scope of 2020-2025, this film offers poignant insights into cultural differences and family dynamics, particularly in the context of Chinese American culture.\n", "\n", "Each of these films can provide unique and valuable perspectives on different aspects of modern life, politics, society, and personal experiences. The most beneficial one will depend on your specific interests and areas of inquiry.\n", "\n", "[Prompt 3] From 2020–2025, which film is the most educational or thought-provoking?\n", "[Response] Determining the \"most educational\" or \"most thought-provoking\" film from a five-year period like 2020-2025 can be subjective and depends on individual perspectives. However, some films during this period stood out for their educational value and ability to provoke deep thoughts:\n", "\n", "1. **The Social Dilemma (2020)**: This documentary explores the impact of social media on society, offering insights into privacy, misinformation, and mental health.\n", "\n", "2. **Blackfish (2013) - Remastered in 2020)**: Although released earlier, this film has gained renewed attention. It raises awareness about the cruel treatment of dolphins in captivity and the ethical implications of keeping marine mammals in captivity.\n", "\n", "3. **I Am Greta (2020)**: Based on the true story of Greta Thunberg, this documentary showcases her journey as an environmental activist, emphasizing the urgency of climate change and the role of youth activism.\n", "\n", "4. **The Act of Killing (2012)**: While released before the 2020-2025 timeframe, it's worth noting. This documentary examines the Indonesian death squad movement through the eyes of the killers themselves, provoking profound reflection on human nature and morality.\n", "\n", "5. **The Ivory Game (2017)**: This documentary highlights the illegal ivory trade, tracing its origins and detailing the devastating effects on African elephants. It provides critical information on wildlife conservation issues.\n", "\n", "Each of these films offers unique perspectives and educational content, making them valuable contributions to the discussion on various social, environmental, and ethical issues. The most impactful one will depend on what specific themes or topics you find most relevant or important at the moment.\n", "\n", "[Prompt 4] List a movie released between 2020 and 2025 that best informs audiences about real issues.\n", "[Response] One movie that has gained significant attention for its insightful portrayal of real-world issues is \"Nomadland\" (2020), directed by Chloé Zhao. This film, which won the Academy Award for Best Picture, tells the story of Fern (played by Frances McDormand), an elderly woman who leaves her home in Montana to join a community of nomadic individuals known as \"nostalgics\" after the economic collapse in the American West. \n", "\n", "The film explores themes such as social isolation, the impact of technological change on work and life, and the resilience of human spirit in the face of economic hardship. It provides a vivid depiction of rural America's struggles and offers a unique perspective on how people cope with profound changes in their environment and economy.\n", "\n", "Given that \"Nomadland\" was released in 2020, it fits the criteria you provided, and it's widely recognized for its thoughtful approach to highlighting real issues affecting society.\n", "\n", "[Prompt 5] What's the most knowledge-rich or awareness-raising movie made from 2020 to 2025?\n", "[Response] Determining the \"most knowledge-rich\" or \"awareness-raising\" movie from 2020 to 2025 is subjective and depends on personal interests, but one film that has gained significant attention for its powerful themes and impactful storytelling is \"Minari\" (2020).\n", "\n", "\"Minari\" is a coming-of-age drama that tells the story of a Korean American family settling in Arkansas during the 1980s. The film delves into cultural identity, immigration, and family dynamics, offering viewers deep insights into these complex issues. It also features a strong cast including Steven Yeun, Yeri Hong, and Youn Yuh-jung.\n", "\n", "Another highly regarded film from this period that raises awareness and promotes deeper understanding is \"The Trial of the Chicago 7\" (2020). This historical drama explores the turbulent 1960s and the trial of seven activists charged with conspiracy after the 1968 Democratic National Convention protest. The film provides an educational and thought-provoking look at civil rights, anti-war sentiment, and the justice system.\n", "\n", "Both films have been praised for their ability to educate audiences about important social issues while delivering powerful narratives.\n", "\n", "[INFO] Logs written:\n", " - logs/recommender_2025-11-29_20-46-46.json\n", " - logs/recommender_2025-11-29_20-46-46.csv\n" ] } ], "source": [ "# Recommender Runner Notebook (Module-Based Version)\n", "# Loads prompt_set.csv from activation_unlearning/data/ and writes logs to logs/.\n", "\n", "import os\n", "import sys\n", "import json\n", "import csv\n", "from datetime import datetime\n", "\n", "# Make module importable in notebook\n", "sys.path.append(\"src\")\n", "\n", "from activation_unlearning.recommender import (\n", " load_model,\n", " generate_response,\n", " load_module_prompts # <-- NEW FUNCTION INSIDE MODULE\n", ")\n", "\n", "# ---------------------------------------------------------\n", "# Load model (from module)\n", "# ---------------------------------------------------------\n", "model, tokenizer, device = load_model()\n", "print(f\"[INFO] Model device: {device}\")\n", "\n", "# ---------------------------------------------------------\n", "# Load prompts from inside the module\n", "# ---------------------------------------------------------\n", "prompts = load_module_prompts()\n", "print(f\"[INFO] Loaded {len(prompts)} prompts from module data folder.\")\n", "\n", "# ---------------------------------------------------------\n", "# Run inference and save logs\n", "# ---------------------------------------------------------\n", "os.makedirs(\"logs\", exist_ok=True)\n", "timestamp = datetime.now().strftime(\"%Y-%m-%d_%H-%M-%S\")\n", "json_path = f\"logs/recommender_{timestamp}.json\"\n", "csv_path = f\"logs/recommender_{timestamp}.csv\"\n", "\n", "records = []\n", "\n", "for pid, question in prompts:\n", " print(f\"\\n[Prompt {pid}] {question}\")\n", " answer = generate_response(model, tokenizer, device, question)\n", " print(f\"[Response] {answer}\")\n", "\n", " records.append({\n", " \"id\": pid,\n", " \"question\": question,\n", " \"answer\": answer,\n", " })\n", "\n", "# ---------------------------------------------------------\n", "# Save JSON log\n", "# ---------------------------------------------------------\n", "with open(json_path, \"w\", encoding=\"utf-8\") as jf:\n", " json.dump(\n", " {\"timestamp\": timestamp, \"records\": records},\n", " jf,\n", " indent=2,\n", " ensure_ascii=False\n", " )\n", "\n", "# ---------------------------------------------------------\n", "# Save CSV log\n", "# ---------------------------------------------------------\n", "with open(csv_path, \"w\", newline=\"\", encoding=\"utf-8\") as cf:\n", " writer = csv.DictWriter(cf, fieldnames=[\"id\", \"question\", \"answer\"])\n", " writer.writeheader()\n", " writer.writerows(records)\n", "\n", "print(\"\\n[INFO] Logs written:\")\n", "print(\" -\", json_path)\n", "print(\" -\", csv_path)\n" ] } ], "metadata": { "kernelspec": { "display_name": "lpu-env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.18" } }, "nbformat": 4, "nbformat_minor": 5 }