27 lines
3.3 KiB
Python
27 lines
3.3 KiB
Python
from transformers import AutoModelForCausalLM, AutoTokenizer, OlmoForCausalLM
|
|
import torch
|
|
|
|
#load in the different models
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-2-0425-1B-Instruct").to(device)
|
|
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-2-0425-1B-Instruct")
|
|
|
|
#priming prompt
|
|
first_prompt = "You are a multi-category classifer model. You are tasked with applying qualitative codes to title-abstract pairs of academic studies. We define the following study characteristics below:"
|
|
characteristics_prompt = "1. English language empirical studies: academic papers written in Egnlish that study or analyze evidence. Literature reviews are not empirical studies. 2. Focus on FOSS projects: is the focus of the research work on the domain of free and open source software projects. 3. Study FOSS project evolution: is the focus of the research work on longitudinal changes to free and open source projects. 4. Study FOSS project adaptation: is the focus of the research work on intentional changes made by free and open source software projects to better align themselves with their broader environment."
|
|
formatting_prompt = "For each code that we have specified, provide a binary YES or NO classification depending on whether or not the code applies to the title-abstract pair. Responses shouldonly include YES or NO responses to each characteristic's inclusion and should be formatted as [characteristic number]:[classification] for ALL four study characteristics that we have defined. Here is the title-abstract pair: "
|
|
|
|
data_prompt = "Title - Underproduction: An Approach for Measuring Risk in Open Source Software \n Abstract - The widespread adoption of Free/Libre and Open Source Software (FLOSS) means that the ongoing maintenance of many widely used software components relies on the collaborative effort of volunteers who set their own priorities and choose their own tasks. We argue that this has created a new form of risk that we call 'underproduction' which occurs when the supply of software engineering labor becomes out of alignment with the demand of people who rely on the software produced. We present a conceptual framework for identifying relative underproduction in software as well as a statistical method for applying our framework to a comprehensive dataset from the Debian GNU/Linux distribution that includes 21,902 source packages and the full history of 461,656 bugs. We draw on this application to present two experiments: (1) a demonstration of how our technique can be used to identify at-risk software packages in a large FLOSS repository and (2) a validation of these results using an alternate indicator of package risk. Our analysis demonstrates both the utility of our approach and reveals the existence of widespread underproduction in a range of widely-installed software components in Debian. "
|
|
|
|
prompt = f"{first_prompt}\n{characteristics_prompt}\n{formatting_prompt}\n{data_prompt}"
|
|
|
|
inputs = tokenizer(prompt, return_tensors='pt', return_token_type_ids=False).to(device)
|
|
|
|
#deterministic sampling
|
|
response = olmo.generate(**inputs, max_new_tokens=256, do_sample=False)
|
|
response_txt = tokenizer.batch_decode(response, skip_special_tokens=True)[0]
|
|
|
|
with open('/home/nws8519/git/adaptation-slr/trial-output.txt', 'w') as file:
|
|
file.write(response_txt)
|
|
|