Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNM: Patch FT Tagger #210

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
DNM: Patch FT Tagger
undfined committed Sep 25, 2024
commit 1a6aec7bb0fe670874a8605944a99cf20b299144
10 changes: 5 additions & 5 deletions python/dolma/core/ft_tagger.py
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@
from fasttext import train_supervised
from fasttext.FastText import _FastText

from .data_types import DocResult, Document, Span, TextSlice
from .taggers import BaseTagger
from .data_types import DocResult, Document, DocumentWithMetadata, Span, TextSlice
from .taggers import BaseTaggerWithMetadata
from .utils import split_paragraphs, split_sentences


@@ -25,7 +25,7 @@ class Prediction(NamedTuple):
score: float


class BaseFastTextTagger(BaseTagger):
class BaseFastTextTagger(BaseTaggerWithMetadata):
SENTENCE_LEVEL_TAGGER = "sentence"
PARAGRAPH_LEVEL_TAGGER = "paragraph"
DOCUMENT_LEVEL_TAGGER = "document"
@@ -135,13 +135,13 @@ def test(
model_performance = classifier.test(local_test_file)
print(model_performance)

def predict(self, doc: Document) -> DocResult:
def predict(self, doc: DocumentWithMetadata) -> DocResult:
if self.mode == self.SENTENCE_LEVEL_TAGGER:
units = split_sentences(doc.text)
elif self.mode == self.PARAGRAPH_LEVEL_TAGGER:
units = split_paragraphs(doc.text)
elif self.mode == self.DOCUMENT_LEVEL_TAGGER:
units = [TextSlice(doc=doc.text, start=0, end=len(doc.text))]
units = [TextSlice(doc=doc.metadata["original_text"], start=0, end=len(doc.metadata["original_text"]))]
else:
raise ValueError(f"Unknown mode {self.mode}")