Skip to main content

Prompt generation for Fragment-Shot and Pivoted Fragment-Shot translation using LLMs

Project description

FragmentShot Retriever

A Python package for retrieving exemplary translations for text based on fragments from parallel corpora.

Features

  • Fragment extraction from source and target texts
  • Configurable maximum fragment size
  • Option to enable or disable fragment overlaps
  • Easy integration for retrieval workflows

Installation

You can install this package locally:

pip install .

Or clone the repo and install in editable mode:

git clone https://github.com/schtailmuel/fragmentshot.git
cd fragmentshot
pip install -e .

Usage

from fragmentshot.retriever import FragmentShotsRetriever

src_texts = [
    "this is a sample source sentence.",
    "another example source sentence."
]

tgt_texts = [
    "dies ist ein Beispiel im Zieltext.",
    "noch ein Beispiel."
]

retriever = FragmentShotsRetriever(src_texts, tgt_texts, max_fragment_size=5, overlaps=False)

result = retriever.get_fragment_shots("The source of this is unknown.")
print(result)

Result

{
  "shots": [
    {
      "index": 1,
      "fragment": "source",
      "examples": [
        {
          "src_text": "this is a sample source sentence.",
          "tgt_text": "dies ist ein Beispiel im Zieltext."
        },
        {
          "src_text": "another example source sentence.",
          "tgt_text": "noch ein Beispiel."
        }
      ]
    },
    {
      "index": 3,
      "fragment": "this is",
      "examples": [
        {
          "src_text": "this is a sample source sentence.",
          "tgt_text": "dies ist ein Beispiel im Zieltext."
        }
      ]
    }
  ],
  "num_words": 6,
  "unknown": [
    "The",
    "of",
    "unknown"
  ]
}

Testing

Run unit tests with:

python -m unittest discover tests

License

This project is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

Created by Samuel Frontull

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

fragmentshot-0.1.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fragmentshot-0.1.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fragmentshot-0.1.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for fragmentshot-0.1.3.tar.gz
Algorithm Hash digest
SHA256 94354d42cf4907bbaae75640654bcf04b457fe8212a72363b3c37a5bc2d59ee0
MD5 6d2991ebcd130dc237369eb2e8c1b61e
BLAKE2b-256 1fd31df57d1155869c44b432c604316c750596ea74fa3abe1eb930df8cef6e6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fragmentshot-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for fragmentshot-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 addbe5727968d13a464d63c9ca18b74df8d9bc95c809e88f13cef33b5879c7ce
MD5 99490133cc7ef47a744a9b14af23c06c
BLAKE2b-256 598474f8cdd1857b9155940e3c315ec74be05893b030a84663cfa15f0c32f364

See more details on using hashes here.

Supported by

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