Code Monkey home page Code Monkey logo

ai_research---temperature-variations-'s Introduction

import json
import argparse
from transformers import AutoModelForCausalLM, AutoTokenizer

class TransformerTextGenerator:
    def __init__(self, model_name_or_path):
        self.model = AutoModelForCausalLM.from_pretrained(model_name_or_path, revision="main")
        self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)

    def generate_text_output(self, prompt, temperature):
        input_ids = self.tokenizer(prompt, return_tensors='pt').input_ids.cuda()
        output = self.model.generate(inputs=input_ids, temperature=temperature, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
        return self.tokenizer.decode(output[0])

def main():
    parser = argparse.ArgumentParser(description="Generate text outputs using a transformer model.")
    parser.add_argument("--input_file", required=True, help="Path to the input JSON file containing input entries.")
    parser.add_argument("--output_file", required=True, help="Path to save the output JSON file with generated text outputs.")
    parser.add_argument("--creative", action="store_true", help="Flag to enable creative mode with varied temperature from 0.5 to 1.0.")
    parser.add_argument("--factual", action="store_true", help="Flag to enable factual mode with varied temperature from 0.5 to 0.0.")
    args = parser.parse_args()

    if args.creative:
        temperature_range = [i / 10 for i in range(5, 11)]  # Temperature range from 0.5 to 1.0
    elif args.factual:
        temperature_range = [i / 10 for i in range(5, -1, -1)]  # Temperature range from 0.5 to 0.0 with decrement of 0.1
    else:
        print("Please specify either --creative or --factual mode.")
        return

    text_generator = TransformerTextGenerator("TheBloke/CapybaraHermes-2.5-Mistral-7B-GPTQ")
    text_outputs = []

    with open(args.input_file, "r") as f:
        input_data = json.load(f)

    for entry in input_data:
        input_text = entry.get("input", "")
        entry_outputs = []
        for temperature in temperature_range:
            text_output = text_generator.generate_text_output(input_text, temperature)
            entry_outputs.append({"temperature": temperature, "text_output": text_output})
        text_outputs.append({"input": input_text, "outputs": entry_outputs})

    with open(args.output_file, "w") as f:
        json.dump(text_outputs, f, indent=4)

if __name__ == "__main__":
    main()

Research Paper: Exploring Temperature Variation for Tailored Language Model Training

By Troy Andrew Schultz

Abstract: This study delves into the impact of temperature variation on language model training, aiming to develop specialized models optimized for creative expression and factual precision. Through systematic experimentation, I investigate how adjusting temperature settings influences the diversity and accuracy of text generation in language models.

Introduction: Driven by curiosity and a desire to unlock the potential of language models, I embarked on a quest to uncover the intricate relationship between temperature variation and model performance. By fine-tuning temperature settings, I aimed to develop models capable of meeting diverse linguistic needs, ranging from creative storytelling to factual reporting.

Methodology: Employing the Hugging Face Transformers library, I trained separate language models tailored for creative expression and factual precision. By adjusting temperature settings within a defined range during training and inference, I sought to optimize model outputs for specific tasks and requirements.

Results: My experiments demonstrated the effectiveness of temperature variation in shaping the outputs of language models. Enabling creative mode with a temperature range from 0.5 to 1.0 enhanced response diversity, fostering imaginative and contextually rich text generation. Conversely, factual mode, with a temperature range from 0.5 to 0.0, yielded precise and evidence-based responses, ideal for tasks requiring factual accuracy.

Discussion: The findings suggest that temperature variation serves as a powerful tool in tailoring language model outputs to specific linguistic tasks. By providing control over temperature settings, I empowered users to fine-tune models for creativity or factual precision, depending on the application at hand.

Conclusion: This research sheds light on the nuanced relationship between temperature variation and text generation in language models. By embracing experimentation and intuitive exploration, I pave the way for the development of specialized models capable of adapting to diverse linguistic needs and improving generalization across different tasks.

Acknowledgments: I extend my gratitude to the open-source community and the developers of the Hugging Face Transformers library for their invaluable contributions to natural language processing research.

Exploring Temperature Variation for Tailored Language Model Training

Introduction

This repository contains code for exploring the impact of temperature variation on language model training. By adjusting temperature settings within a defined range, we aim to develop specialized language models optimized for creative expression and factual precision.

ai_research---temperature-variations-'s People

Contributors

troys-code avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.