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 fragmentshot

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

Citation

If you use this code in your research, please cite our paper (preprint):

@misc{frontull:stroehle:2025,
      title={Compensating for Data with Reasoning: Low-Resource Machine Translation with LLMs}, 
      author={Samuel Frontull and Thomas Ströhle},
      year={2025},
      eprint={2505.22293},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2505.22293}, 
}

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.5.tar.gz (4.4 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.5-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fragmentshot-0.1.5.tar.gz
  • Upload date:
  • Size: 4.4 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.5.tar.gz
Algorithm Hash digest
SHA256 c1f9426bf4fb73ef6fec615c16f6cebb937c4d99beec50518527b32dff4691cf
MD5 ae25fcac4127e8a67bf78ac25b4c4c23
BLAKE2b-256 f848464c09affb85572d5ef23b8712ffb44efe78c44ac9efd056a9a5b20bac00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fragmentshot-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c3c77ad3c0115cf2fb90c147797704364293db7eedc5b612398e26ec884fd554
MD5 c659f8dffb4ac02b55829d99dfa8f945
BLAKE2b-256 1e550ff164a35c62bfa54d03f6447a26eebea78d2a0de53203af712d4613da2c

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