dstpr 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dstpr
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A high-throughput, domain-specific text preprocessing cascading pipeline filter to rank core sentences in texts and filter away boilerplate.
5
5
  Author-email: Stephen Meisenbacher <sjmeis@gtgd.com>
6
6
  Maintainer-email: Stephen Meisenbacher <sjmeis@gtgd.com>
@@ -94,8 +94,8 @@ If you want to integrate specific pipeline layers directly into an existing work
94
94
  ```python
95
95
  from dstpr.cleaners import clean_and_split_chunks
96
96
  from dstpr.segmenters import SemanticSectionRouter
97
- from dstpr.rankers import HybridTaskRanker
98
- from sentence_transformers import Transformer, SentenceTransformer
97
+ from dstpr.rankers import HybridRanker
98
+ from sentence_transformers import SentenceTransformer
99
99
 
100
100
  embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
101
101
 
@@ -110,7 +110,7 @@ buckets = router.route_sentences(sentences)
110
110
  target_sentences = buckets['CORE'] + buckets['REQUIREMENTS']
111
111
 
112
112
  # Grade and sort text features
113
- ranker = HybridRanker(model=shared_model)
113
+ ranker = HybridRanker()
114
114
  final = ranker.rank_and_filter(target_sentences, bi_cutoff_pct=0.25, final_threshold=0.40)
115
115
  ```
116
116
 
@@ -54,8 +54,8 @@ If you want to integrate specific pipeline layers directly into an existing work
54
54
  ```python
55
55
  from dstpr.cleaners import clean_and_split_chunks
56
56
  from dstpr.segmenters import SemanticSectionRouter
57
- from dstpr.rankers import HybridTaskRanker
58
- from sentence_transformers import Transformer, SentenceTransformer
57
+ from dstpr.rankers import HybridRanker
58
+ from sentence_transformers import SentenceTransformer
59
59
 
60
60
  embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
61
61
 
@@ -70,7 +70,7 @@ buckets = router.route_sentences(sentences)
70
70
  target_sentences = buckets['CORE'] + buckets['REQUIREMENTS']
71
71
 
72
72
  # Grade and sort text features
73
- ranker = HybridRanker(model=shared_model)
73
+ ranker = HybridRanker()
74
74
  final = ranker.rank_and_filter(target_sentences, bi_cutoff_pct=0.25, final_threshold=0.40)
75
75
  ```
76
76
 
@@ -47,14 +47,14 @@ class ParallelPreprocessingPipeline:
47
47
  print(f"GPU Auto-Calibrated Batch Size: {self.inference_batch_size}")
48
48
 
49
49
  dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16
50
- bi_encoder = SentenceTransformer(
50
+ self.bi_encoder = SentenceTransformer(
51
51
  self.embedding_model,
52
52
  device="cuda",
53
53
  model_kwargs={"dtype": dtype}
54
54
  )
55
55
 
56
- cross_encoder = CrossEncoder(
57
- "cross-encoder/ms-marco-MiniLM-L-6-v2",
56
+ self.cross_encoder = CrossEncoder(
57
+ "cross-encoder/ms-marco-MiniLM-L6-v2",
58
58
  device="cuda",
59
59
  model_kwargs={"dtype": dtype}
60
60
  )
@@ -63,11 +63,11 @@ class ParallelPreprocessingPipeline:
63
63
  self.bi_encoder = SentenceTransformer(self.embedding_model, device=device)
64
64
  self.cross_encoder = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2", device=device)
65
65
 
66
- self.router = SemanticSectionRouter(profile=self.profile, model=bi_encoder)
66
+ self.router = SemanticSectionRouter(profile=self.profile, model=self.bi_encoder)
67
67
  self.ranker = HybridRanker(
68
68
  profile=self.profile,
69
- model=bi_encoder,
70
- cross_encoder_model=cross_encoder,
69
+ model=self.bi_encoder,
70
+ cross_encoder_model=self.cross_encoder,
71
71
  )
72
72
  self._is_initialized = True
73
73
 
@@ -115,8 +115,7 @@ class ParallelPreprocessingPipeline:
115
115
 
116
116
  filtered_doc_sentences = self.ranker.rank_and_filter(
117
117
  sentences=doc_candidates,
118
- batch_size=self.inference_batch_size,
119
- final_threshold=threshold
118
+ batch_size=self.inference_batch_size
120
119
  )
121
120
 
122
121
  return [sanitize_outputs(sents, self.profile) for sents in filtered_doc_sentences]
@@ -14,7 +14,7 @@ class HybridRanker:
14
14
  self.cross_encoder = (
15
15
  cross_encoder_model
16
16
  if cross_encoder_model
17
- else CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
17
+ else CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")
18
18
  )
19
19
 
20
20
  with torch.inference_mode():
@@ -61,7 +61,6 @@ class HybridRanker:
61
61
  sentences: list[list[str]],
62
62
  high_certainty_threshold: float = 0.60,
63
63
  low_certainty_threshold: float = 0.20,
64
- final_threshold: float = 0.40,
65
64
  batch_size: int = 512
66
65
  ) -> list[list[str]]:
67
66
  flat_candidates = []
@@ -108,6 +107,24 @@ class HybridRanker:
108
107
  )
109
108
 
110
109
  cross_keep_set = set()
110
+ if needs_cross:
111
+ primary_anchor = self.profile.positive_semantic_anchors[0]
112
+ cross_inputs = [[primary_anchor, sent] for sent in needs_cross]
113
+
114
+ cross_scores = self.cross_encoder.predict(
115
+ cross_inputs,
116
+ batch_size=batch_size,
117
+ show_progress_bar=False,
118
+ convert_to_tensor=True,
119
+ )
120
+
121
+ with torch.inference_mode():
122
+ survived_flags = (cross_scores >= 0.0).cpu().tolist()
123
+
124
+ cross_keep_set = set(
125
+ [sent for sent, keep in zip(needs_cross, survived_flags) if keep]
126
+ )
127
+
111
128
  surviving_mask = [False] * len(flat_candidates)
112
129
  for idx, is_auto in enumerate(auto_mask):
113
130
  if is_auto:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dstpr
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A high-throughput, domain-specific text preprocessing cascading pipeline filter to rank core sentences in texts and filter away boilerplate.
5
5
  Author-email: Stephen Meisenbacher <sjmeis@gtgd.com>
6
6
  Maintainer-email: Stephen Meisenbacher <sjmeis@gtgd.com>
@@ -94,8 +94,8 @@ If you want to integrate specific pipeline layers directly into an existing work
94
94
  ```python
95
95
  from dstpr.cleaners import clean_and_split_chunks
96
96
  from dstpr.segmenters import SemanticSectionRouter
97
- from dstpr.rankers import HybridTaskRanker
98
- from sentence_transformers import Transformer, SentenceTransformer
97
+ from dstpr.rankers import HybridRanker
98
+ from sentence_transformers import SentenceTransformer
99
99
 
100
100
  embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
101
101
 
@@ -110,7 +110,7 @@ buckets = router.route_sentences(sentences)
110
110
  target_sentences = buckets['CORE'] + buckets['REQUIREMENTS']
111
111
 
112
112
  # Grade and sort text features
113
- ranker = HybridRanker(model=shared_model)
113
+ ranker = HybridRanker()
114
114
  final = ranker.rank_and_filter(target_sentences, bi_cutoff_pct=0.25, final_threshold=0.40)
115
115
  ```
116
116
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dstpr"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "A high-throughput, domain-specific text preprocessing cascading pipeline filter to rank core sentences in texts and filter away boilerplate."
9
9
  readme = {file = "README.md", content-type = "text/markdown"}
10
10
  license = {file = "LICENSE"}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes