From 7fe1666b1170f0b79b446785f8411d8e216769da Mon Sep 17 00:00:00 2001 From: mauryaland Date: Wed, 15 Mar 2023 22:55:38 +0100 Subject: [PATCH] take into account Sentence.start_position to calculate whitespace --- flair/data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flair/data.py b/flair/data.py index 2722a85510..de969a1083 100644 --- a/flair/data.py +++ b/flair/data.py @@ -917,7 +917,9 @@ def to_original_text(self) -> str: if len(self) == 0: return "" # otherwise, return concatenation of tokens with the correct offsets - return self[0].start_position * " " + "".join([t.text + t.whitespace_after * " " for t in self.tokens]).strip() + return (self[0].start_position - self.start_position) * " " + "".join( + [t.text + t.whitespace_after * " " for t in self.tokens] + ).strip() def to_dict(self, tag_type: str = None): labels = []