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.2.tar.gz (67.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: LangTorch-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 2a9b1cf7787ceb90fa9afdde0cec3c2adf5e6604894cbb6fd6fe74314dadd32e
MD5 4469164d9a167f167fe1a3cbe112eebf
BLAKE2b-256 0ca623f6ce5a31bb53daed778abeab6c60c0a0eff0c13297afaa91bd17fbd148

See more details on using hashes here.

File details

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

File metadata

  • Download URL: LangTorch-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad64daa323ba33d778e056f01404dd8bd3fd36c54732ea67f5b48553dc605c5b
MD5 39bcb43aaafac76bc300aff6ce669e00
BLAKE2b-256 44bcc26280576d9d86e8b858e3006410160c0bdbba6154965bac9fd51ba4b555

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