{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcfcd3e1",
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "#https://huggingface.co/allenai/OLMo-2-1124-13B-Instruct-GGUF\n",
    "#https://huggingface.co/allenai/OLMo-2-0425-1B-Instruct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d5cf1e46-0cf2-4a55-869c-ac1f43f986fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM, AutoTokenizer, OlmoForCausalLM\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "69e68a80-1a85-4009-8120-fcef79ae1c17",
   "metadata": {},
   "outputs": [],
   "source": [
    "olmo = AutoModelForCausalLM.from_pretrained(\n",
    "    \"allenai/OLMo-2-0425-1B-Instruct\" \n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e4930b9-1d20-4d49-bb6e-e1a06aa91f52",
   "metadata": {},
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained(\"allenai/OLMo-2-0425-1B-Instruct\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "99515b35-7f18-4327-b722-653bb034da63",
   "metadata": {},
   "outputs": [],
   "source": [
    "classification_prompt = [\"Prompt: Title-Abstract Classification Task \\n Study Characteristics: \\n English Empirical Studies: Academic papers in English that study or analyze empirical evidence, excluding literature reviews. \\n FOSS Focus: Research focused primarily on the domain of free and open source software (FOSS) projects.\\n FOSS Project Evolution: Research specifically examining longitudinal changes to FOSS projects. \\n FOSS Project Adaptation: Research centered on intentional changes made by FOSS projects to better align themselves with their broader environment. \\n Task Instructions: For each of the four study characteristics listed above (1-4), indicate the presence of the characteristic in the given title-abstract pair with a 'yes' or 'no' label. \\n\\n **Title: Underproduction: An Approach for Measuring Risk in Open Source Software** \\n **Abstract: The widespread adoption of Free/Libre and Open Source Software (FLOSS) implies that the maintenance of widely used software components relies on volunteer effort. We identify 'underproduction' as a new risk when labor supply and demand are misaligned. We present a framework and a statistical method applied to a comprehensive dataset from the Debian GNU/Linux distribution. Two experiments are presented to demonstrate our approach's utility and reveal widespread underproduction.** \\n\\n Processing Instructions for AI: \\n Read the title and abstract carefully. Measure the relevance of each study characteristic against the provided title and abstract. Please respond with a 'yes' or 'no' for each characteristic. \\n Note: Your responses should be based solely on the given title and abstract. No external information should be considered.\"]\n",
    "classification_inputs = tokenizer(classification_prompt, return_tensors='pt', return_token_type_ids=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f265fa66-5105-47c1-ac81-7ec3906c9bd9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#do_sample = False sets it to deterministic sampling \n",
    "trial_response = olmo.generate(\n",
    "    **classification_inputs,\n",
    "    max_new_tokens=256,\n",
    "    do_sample=False\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8fc2f1c0-5865-4209-b18c-909937e69f05",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prompt: Title-Abstract Classification Task \n",
      " Study Characteristics: \n",
      " English Empirical Studies: Academic papers in English that study or analyze empirical evidence, excluding literature reviews. \n",
      " FOSS Focus: Research focused primarily on the domain of free and open source software (FOSS) projects.\n",
      " FOSS Project Evolution: Research specifically examining longitudinal changes to FOSS projects. \n",
      " FOSS Project Adaptation: Research centered on intentional changes made by FOSS projects to better align themselves with their broader environment. \n",
      " Task Instructions: For each of the four study characteristics listed above (1-4), indicate the presence of the characteristic in the given title-abstract pair with a 'yes' or 'no' label. \n",
      "\n",
      " **Title: Underproduction: An Approach for Measuring Risk in Open Source Software** \n",
      " **Abstract: The widespread adoption of Free/Libre and Open Source Software (FLOSS) implies that the maintenance of widely used software components relies on volunteer effort. We identify 'underproduction' as a new risk when labor supply and demand are misaligned. We present a framework and a statistical method applied to a comprehensive dataset from the Debian GNU/Linux distribution. Two experiments are presented to demonstrate our approach's utility and reveal widespread underproduction.** \n",
      "\n",
      " Processing Instructions for AI: \n",
      " Read the title and abstract carefully. Measure the relevance of each study characteristic against the provided title and abstract. Please respond with a 'yes' or 'no' for each characteristic. \n",
      " Note: Your responses should be based solely on the given title and abstract. No external information should be considered. If you encounter any ambiguity, the title alone should be sufficient to answer the question. \n",
      "\n",
      "**Example:** For the study focusing on effect of leadership on software quality, if the title mentions \"leadership\" and the abstract talks about \"the influence of team size on software quality\", the response would be 'yes'. \n",
      "\n",
      "**Answering the prompt:** For the given title and abstract, the characteristic 'underproduction' is not mentioned. Therefore, the answer is 'no'. \n",
      "\n",
      "**Instructions:** Based on the provided information, indicate whether the study focuses on 'underproduction' in the given title-abstract pair. \n",
      "**Answer:** no\n"
     ]
    }
   ],
   "source": [
    "print(tokenizer.batch_decode(trial_response, skip_special_tokens=True)[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
