# FormatAI: Structuring Unstructured Text using generative AI

- Speaker: [Oren Matar](/wiki/speakers/oren-matar.md)
- Event: [Reversim Summit 2024](/wiki/years/2024.md)
- Video: https://www.youtube.com/watch?v=kpqYcjoVmoI
- Transcript: [/transcripts/2024/47-kpqYcjoVmoI.md](/transcripts/2024/47-kpqYcjoVmoI.md)
- Language: Hebrew · Type: talk · Level: advanced
- Topics: [Machine Learning](/wiki/topics/machine-learning.md), [AI and LLMs](/wiki/topics/generative-ai.md), [Data Science](/wiki/topics/data-science.md), [Architecture](/wiki/topics/architecture.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker shares a project focused on extracting time ranges from natural language queries to support self-service business analytics. Instead of relying purely on large language models or rigid regular expressions, the team developed a custom structured language and trained a small encoder-decoder model. By separating natural language understanding from business logic and constraining the model generation, they achieved high accuracy and flexibility. The audience learns a practical paradigm for structuring unstructured text efficiently using small machine learning models.

## Key points

- [2:16](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=136s) The goal is to enable self-service analytics where users can query complex business data using natural language.
- [4:32](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=272s) Using general-purpose language models for complex logical reasoning about dates proved unreliable, slow, and expensive.
- [6:39](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=399s) The first core principle is separating language extraction from logical operations by introducing a dedicated Structured Time Language.
- [8:52](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=532s) The architecture uses an encoder-decoder model combined with a classifier for named entity recognition to extract and tag time expressions.
- [11:14](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=674s) The second principle involves rapidly generating a large synthetic dataset using programmatic rules and data augmentation.
- [17:46](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=1066s) The third principle is structural generation, constraining the decoder's logits to ensure outputs always follow the strict rules of the target language.
- [21:00](https://www.youtube.com/watch?v=kpqYcjoVmoI&t=1260s) Careful attention to tokenization ensures that symbols map consistently to single meanings without confusing the classifier.

## Takeaways

- Separate language understanding from business logic when parsing unstructured text into structured formats.
- Build synthetic datasets programmatically to quickly scale training data and iterate on edge cases.
- Use logits processors to constrain small language models and guarantee syntactically valid outputs.

## Questions this talk answers

- How can I extract structured data from natural language without relying solely on expensive large language models?
- What is the best way to guarantee that a sequence-to-sequence model only outputs syntactically valid domain-specific language?
- How can I programmatically generate a robust training dataset for time range extraction?

## Technologies

Python, PyCharm, Hugging Face, SQL, Jira

## Tags

analytics, architecture, data extraction, generative ai, machine learning, nlp, transformers
