Skip to main content

Framework for intuitive LLM application development with tensors.

Project description

LangTorch Logo LangTorch

Release Notes Downloads License: MIT Twitter GitHub star chart

LangTorch is a Python package designed to simplify the development of LLM applications by leveraging familiar PyTorch concepts.

Installation

pip install langtorch

Overview

LangTorch provides a structured approach to LLM applications, offering:

  • TextTensors: A unified way to handle prompt templates, completion dictionaries, and chat histories.
  • TextModules: Building blocks, derived from torch.nn.Module, specifically tailored for text operations and LLM calls both locally and via an API.
  • other things that are also better than langchain

Examples

TextTensors

Creating and manipulating textual data as tensors:

template = TextTensor([["Explain {theory} in terms of {framework}"],  
                       ["Argue how {framework} can prove {theory}"]])  

result = template * TextTensor({"theory": "active inference", "framework": "thermodynamics" })

print(result)
# Outputs: [[Explain active inference in terms of thermodynamics]
#           [Argue how thermodynamics can prove active inference]]

TextModules

Building sequences of operations on text data:

chain = torch.nn.Sequential(
    TextModule("Calculate this equation: {}"),
    langtorch.methods.CoT,
    GPT4
    TextModule("Is this reasoning correct? {}", activation = GPT4)
)

output = chain(TextTensor(["170*32 =", "4*20 =", "123*45/10 =", "2**10*5 ="]))

Cosine Similarities

Compute similarities between entries:

from langtorch.tt import CosineSimilarity

cos = CosineSimilarity()
similarities = cos(TextTensor([["Yes"], ["No"]]), TextTensor(["1", "0", "Noo", "Yees"]))

Contribute

Your feedback and contributions are valued. Feel free to check out our contribution guidelines.

License

LangTorch is MIT licensed. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

LangTorch-0.1.3.tar.gz (67.4 kB view details)

Uploaded Source

Built Distribution

LangTorch-0.1.3-py3-none-any.whl (96.0 kB view details)

Uploaded Python 3

File details

Details for the file LangTorch-0.1.3.tar.gz.

File metadata

  • Download URL: LangTorch-0.1.3.tar.gz
  • Upload date:
  • Size: 67.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for LangTorch-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a6079b080c03540c43eb5a3ddf6296c839d5bf7d1f74f905cb3f70e21b6e9b35
MD5 0afaf2bfafcae6b2590d48a2e45a63be
BLAKE2b-256 39add5188854c3363d049199fd6975e1344a9c8ca29b09a1d2c386acca5649a8

See more details on using hashes here.

File details

Details for the file LangTorch-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: LangTorch-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 96.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for LangTorch-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a37d0577be4338fac9d0fee7ec8e5b749234ec9ab4b47d49b43dafb458a0ae1c
MD5 bdf783237f9db9eefdde5380f119637b
BLAKE2b-256 cf506833601b8073090701eabf7f0713fc36a86b48a595331ef86c6b81911671

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page