GithubHelp home page GithubHelp logo

jonasi / langdspy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aelaguiz/langdspy

0.0 0.0 0.0 256 KB

Declarative prompting compatible with langchain, scikit-learn. Enterprise ready.

Python 100.00%

langdspy's Introduction

langdspy: Langchain implementation of stanford DSPy

This is intended to be a langchain native implementation of the innovative principles pioneered by the wonderful DSPy

I believe that the principles they have pioneered should be built on top of more mature primitives with a larger ecosystem & community to support it.

This is intended to be usable in production enterprise environments.

Designed to be interface compatible with both langchain and scikit-learn.

Example in action

Automatically tunning n-shot prompts based on provided samples. See examples/amazon/generate_slugs.py

if __name__ == "__main__":
    output_path = sys.argv[1]
    dataset_file= "data/amazon_products_split.json"
    with open(dataset_file, 'r') as file:
        dataset = json.load(file)
    
    X_train = dataset['train']['X']
    y_train = dataset['train']['y']
    X_test = dataset['test']['X']
    y_test = dataset['test']['y']
    
    model = ProductSlugGenerator(n_jobs=4, print_prompt=True)

    before_test_accuracy = None
    if os.path.exists(output_path):
        model.load(output_path)
    else:
        input("Hit enter to evaluate the untrained model...")
        before_test_accuracy = evaluate_model(model, X_test, y_test)
        print(f"Before Training Accuracy: {before_test_accuracy}")
        
        input("Hit enter to train the model...")
        model.fit(X_train, y_train, score_func=slug_similarity, llm=llm, n_examples=2, n_iter=100)
        
    input("Hit enter to evaluate the trained model...")
    # Evaluate the model on the test set
    test_accuracy = evaluate_model(model, X_test, y_test)
    print(f"Before Training Accuracy: {before_test_accuracy}")
    print(f"After Training Accuracy: {test_accuracy}")

    model.save(output_path)

Quick start

git clone https://github.com/aelaguiz/langdspy
cd langdspy
pip install poetry
poetry install
poetry run test

Roadmap

  • Unit tests
  • Auto-Tuning with RAG steps
  • New prmompt strategies (e.g. Chain Of Thought)
  • Tighter integration with Langchain templates (can we use their few-shot prompting templates for example?)

Author

Amir Elaguizy is the original author but sincerely hopes to be the smallest piece of this going forward.

Use it as you wish.

langdspy's People

Contributors

aelaguiz avatar schultz-is avatar rblakemesser avatar jonasi 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.