From 2bf80e40762a3e7a62ebcc89640f9a6deda2d3ea Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 3 Apr 2023 07:19:06 +0200 Subject: Fix memory leak --- data/csv.py | 5 +---- data/keywords.py | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'data') diff --git a/data/csv.py b/data/csv.py index d0ac317..e1b92c1 100644 --- a/data/csv.py +++ b/data/csv.py @@ -142,10 +142,7 @@ class VlpnDataItem(NamedTuple): collection: list[str] def full_prompt(self, dropout: float = 0, shuffle: bool = False): - prompt = self.prompt - if len(self.keywords): - prompt += ", " + keywords_to_str(self.keywords, dropout, shuffle) - return prompt + return keywords_to_str(self.keywords, [self.prompt], dropout, shuffle) def keyword_filter( diff --git a/data/keywords.py b/data/keywords.py index 7385809..629006d 100644 --- a/data/keywords.py +++ b/data/keywords.py @@ -1,9 +1,12 @@ import numpy as np -def keywords_to_str(keywords: list[str], dropout: float = 0, shuffle: bool = False) -> str: +def keywords_to_str(keywords: list[str], undroppable_keywords: list[str] = [], dropout: float = 0, shuffle: bool = False) -> str: if dropout != 0: keywords = [keyword for keyword in keywords if np.random.random() > dropout] + else: + keywords = keywords.copy() + keywords += undroppable_keywords if shuffle: np.random.shuffle(keywords) return ", ".join(keywords) -- cgit v1.2.3-70-g09d2