Skip to content

Commit a4b2bcd

Browse files
rmitschRaphael Mitsch
andauthored
feat: Add relation extraction task (#242)
* feat: Foundation for relation extraction. * docs: Update docs. * fix: Fix relation extraction bugs. * chore: Clean up RE bridge. * chore: Clean up. * fix: Make context field optional. --------- Co-authored-by: Raphael Mitsch <raphael@climatiq.com>
1 parent a4b4aff commit a4b2bcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1639
-673
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ to skip having to define tasks from scratch.
5353
- :label: **Ready-to-Use Tasks:**
5454
- Multi-label classification
5555
- Information extraction
56+
- Relation extraction
5657
- Summarization
5758
- Translation
5859
- Multi-question answering

docs/tasks/predictive/classification.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `Classification` task categorizes documents into predefined labels.
1515
The `Classification` task returns a unified result schema regardless of the model backend used.
1616

1717
```python
18-
--8<-- "sieves/tasks/predictive/classification/schemas.py:Result"
18+
--8<-- "sieves/tasks/predictive/schemas/classification.py:Result"
1919
```
2020

2121
- When `multi_label=True` (default): results are of type `ResultMultiLabel`, containing a list of `(label, score)` tuples.
@@ -25,4 +25,4 @@ The `Classification` task returns a unified result schema regardless of the mode
2525

2626
::: sieves.tasks.predictive.classification.core
2727
::: sieves.tasks.predictive.classification.bridges
28-
::: sieves.tasks.predictive.classification.schemas
28+
::: sieves.tasks.predictive.schemas.classification

docs/tasks/predictive/information_extraction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Use `mode="single"` when you expect exactly one entity per document (or none). T
2525
The `InformationExtraction` task produces unified results based on the chosen mode:
2626

2727
```python
28-
--8<-- "sieves/tasks/predictive/information_extraction/schemas.py:Result"
28+
--8<-- "sieves/tasks/predictive/schemas/information_extraction.py:Result"
2929
```
3030

3131
- `mode="multi"`: Returns a `ResultMulti` object with an `entities` list.
@@ -35,4 +35,4 @@ The `InformationExtraction` task produces unified results based on the chosen mo
3535

3636
::: sieves.tasks.predictive.information_extraction.core
3737
::: sieves.tasks.predictive.information_extraction.bridges
38-
::: sieves.tasks.predictive.information_extraction.schemas
38+
::: sieves.tasks.predictive.schemas.information_extraction

docs/tasks/predictive/ner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Providing descriptions for each entity type helps the model understand exactly w
2525
The `NER` task returns a unified `Result` object (an alias for `Entities`) containing a list of `Entity` objects and the source text.
2626

2727
```python
28-
--8<-- "sieves/tasks/predictive/ner/schemas.py:Result"
28+
--8<-- "sieves/tasks/predictive/schemas/ner.py:Result"
2929
```
3030

3131
---
3232

3333
::: sieves.tasks.predictive.ner.core
3434
::: sieves.tasks.predictive.ner.bridges
35-
::: sieves.tasks.predictive.ner.schemas
35+
::: sieves.tasks.predictive.schemas.ner

docs/tasks/predictive/pii_masking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ The `PIIMasking` task identifies and masks Personally Identifiable Information (
1313
The `PIIMasking` task returns a unified `Result` object containing the `masked_text` and a list of `pii_entities`.
1414

1515
```python
16-
--8<-- "sieves/tasks/predictive/pii_masking/schemas.py:Result"
16+
--8<-- "sieves/tasks/predictive/schemas/pii_masking.py:Result"
1717
```
1818

1919
---
2020

2121
::: sieves.tasks.predictive.pii_masking.core
2222
::: sieves.tasks.predictive.pii_masking.bridges
23-
::: sieves.tasks.predictive.pii_masking.schemas
23+
::: sieves.tasks.predictive.schemas.pii_masking

docs/tasks/predictive/question_answering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ The `QuestionAnswering` task answers questions based on the content of the docum
1313
The `QuestionAnswering` task returns a unified `Result` object containing a list of `answers` corresponding to the input questions.
1414

1515
```python
16-
--8<-- "sieves/tasks/predictive/question_answering/schemas.py:Result"
16+
--8<-- "sieves/tasks/predictive/schemas/question_answering.py:Result"
1717
```
1818

1919
---
2020

2121
::: sieves.tasks.predictive.question_answering.core
2222
::: sieves.tasks.predictive.question_answering.bridges
23-
::: sieves.tasks.predictive.question_answering.schemas
23+
::: sieves.tasks.predictive.schemas.question_answering
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Relation Extraction
2+
3+
The `RelationExtraction` task performs joint entity and relation extraction, identifying relationships between entities in text.
4+
5+
## Usage
6+
7+
```python
8+
--8<-- "sieves/tests/tasks/predictive/test_relation_extraction.py:re-usage"
9+
```
10+
11+
## Results
12+
13+
The `RelationExtraction` task returns a unified `Result` object containing a list of `RelationTriplet` objects.
14+
15+
```python
16+
--8<-- "sieves/tasks/predictive/schemas/relation_extraction.py:Result"
17+
```
18+
19+
Each `RelationTriplet` consists of:
20+
- `head`: A `RelationEntity` representing the subject.
21+
- `relation`: The string identifier of the relationship.
22+
- `tail`: A `RelationEntity` representing the object.
23+
24+
A `RelationEntity` includes the surface `text`, `entity_type`, and character `start`/`end` offsets.
25+
26+
---
27+
28+
::: sieves.tasks.predictive.relation_extraction.core
29+
::: sieves.tasks.predictive.relation_extraction.bridges
30+
::: sieves.tasks.predictive.schemas.relation_extraction

docs/tasks/predictive/sentiment_analysis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ The `SentimentAnalysis` task determines the sentiment of the text (e.g., positiv
1313
The `SentimentAnalysis` task returns a unified `Result` object containing a `sentiment_per_aspect` dictionary.
1414

1515
```python
16-
--8<-- "sieves/tasks/predictive/sentiment_analysis/schemas.py:Result"
16+
--8<-- "sieves/tasks/predictive/schemas/sentiment_analysis.py:Result"
1717
```
1818

1919
---
2020

2121
::: sieves.tasks.predictive.sentiment_analysis.core
2222
::: sieves.tasks.predictive.sentiment_analysis.bridges
23-
::: sieves.tasks.predictive.sentiment_analysis.schemas
23+
::: sieves.tasks.predictive.schemas.sentiment_analysis

docs/tasks/predictive/summarization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ The `Summarization` task generates concise summaries of the documents.
1313
The `Summarization` task returns a unified `Result` object containing the `summary`.
1414

1515
```python
16-
--8<-- "sieves/tasks/predictive/summarization/schemas.py:Result"
16+
--8<-- "sieves/tasks/predictive/schemas/summarization.py:Result"
1717
```
1818

1919
---
2020

2121
::: sieves.tasks.predictive.summarization.core
2222
::: sieves.tasks.predictive.summarization.bridges
23-
::: sieves.tasks.predictive.summarization.schemas
23+
::: sieves.tasks.predictive.schemas.summarization

docs/tasks/predictive/translation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ The `Translation` task translates documents into a target language.
1313
The `Translation` task returns a unified `Result` object containing the `translation`.
1414

1515
```python
16-
--8<-- "sieves/tasks/predictive/translation/schemas.py:Result"
16+
--8<-- "sieves/tasks/predictive/schemas/translation.py:Result"
1717
```
1818

1919
---
2020

2121
::: sieves.tasks.predictive.translation.core
2222
::: sieves.tasks.predictive.translation.bridges
23-
::: sieves.tasks.predictive.translation.schemas
23+
::: sieves.tasks.predictive.schemas.translation

0 commit comments

Comments
 (0)