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

Uploaded Source

Built Distribution

LangTorch-0.1.9-py3-none-any.whl (149.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: LangTorch-0.1.9.tar.gz
  • Upload date:
  • Size: 89.3 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.9.tar.gz
Algorithm Hash digest
SHA256 0718fb140b8b774f9d7c603206a416eafef842e16010bed8cdd4f7cee12489bf
MD5 179dd69893f2b40823c4b9c6ae295861
BLAKE2b-256 8ca35779a72931dd8f930f2a1f8346d6d0f1ec915d11cc3842de22eb3c8342c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: LangTorch-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 149.6 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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 db69acf53f7a51bbf945b34f65f1275077819cdd0e89816b60d61a1583aa9659
MD5 fd77271558bb9c9add64843ffe72e13f
BLAKE2b-256 b8c9b59ca40c2ff369ce6428b43e3c1ccc8fa172c0ce202629bbc7f204945aab

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