💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Pipeline updates
davidmezzettib42a25253887
diff --git a/src/python/txtai/pipeline/summary.py b/src/python/txtai/pipeline/summary.pyindex 46fcd9e9..cb371068 100644--- a/src/python/txtai/pipeline/summary.py+++ b/src/python/txtai/pipeline/summary.py@@ -31,21 +31,30 @@ class Summary(HFPipeline):summary text"""+ # Validate text length greater than max length+ check = maxlength if maxlength else self.pipeline.model.config.max_length++ # Skip text shorter than max length+ texts = text if isinstance(text, list) else [text]+ params = [(x, text if len(text) >= check else None) for x, text in enumerate(texts)]+kwargs = {"truncation": True}if minlength:kwargs["min_length"] = minlengthif maxlength:kwargs["max_length"] = maxlength- # Run summarization pipeline- results = self.pipeline(text, **kwargs)-- # Convert results to a list if necessary- if not isinstance(results, list):- results = [results]-- # Pull out summary text- results = [self.clean(x["summary_text"]) for x in results]+ inputs = [text for _, text in params if text]+ if inputs:+ # Run summarization pipeline+ results = self.pipeline(inputs, **kwargs)++ # Pull out summary text+ results = iter([self.clean(x["summary_text"]) for x in results])+ results = [next(results) if text else texts[x] for x, text in params]+ else:+ # Return original+ results = textsreturn results[0] if isinstance(text, str) else resultsdiff --git a/src/python/txtai/pipeline/textractor.py b/src/python/txtai/pipeline/textractor.pyindex 2a3a83f5..1c4fc652 100644--- a/src/python/txtai/pipeline/textractor.py+++ b/src/python/txtai/pipeline/textractor.py@@ -15,18 +15,20 @@ class Textractor(Pipeline):Extracts text from files."""- def __init__(self, sentences=False, paragraphs=False, minlength=None, join=False):+ def __init__(self, sentences=False, lines=False, paragraphs=False, minlength=None, join=False):"""Creates a new Textractor.Args:sentences: tokenize text into sentences if True, defaults to False+ lines: tokenizes text into lines if True, defaults to Falseparagraphs: tokenizes text into paragraphs if True, defaults to Falseminlength: require at least minlength characters per text element, defaults to Nonejoin: joins tokenized sections back together if True, defaults to False"""self.sentences = sentences+ self.lines = linesself.paragraphs = paragraphsself.minlength = minlengthself.join = join@@ -76,6 +78,8 @@ class Textractor(Pipeline):if self.sentences:content = [self.clean(x) for x in sent_tokenize(text)]+ elif self.lines:+ content = [self.clean(x) for x in text.split("\n")]elif self.paragraphs:content = [self.clean(x) for x in text.split("\n\n")]else:@@ -84,7 +88,7 @@ class Textractor(Pipeline):# Remove empty stringscontent = [x for x in content if x]- if self.sentences or self.paragraphs:+ if self.sentences or self.lines or self.paragraphs:return " ".join(content) if self.join else contentreturn content[0]diff --git a/src/python/txtai/pipeline/translation.py b/src/python/txtai/pipeline/translation.pyindex b93b6d7c..be340d2d 100644--- a/src/python/txtai/pipeline/translation.py+++ b/src/python/txtai/pipeline/translation.py@@ -116,7 +116,7 @@ class Translation(HFModel):self.detector = fasttext.load_model(path)# Transform texts to format expected by language detection model- texts = [x.lower() for x in texts]+ texts = [x.lower().replace("\n", " ").replace("\r\n", " ") for x in texts]return [x[0].split("__")[-1] for x in self.detector.predict(texts)[0]]