davidheineman commited on
Commit
992c5b6
1 Parent(s): 8f175aa

add more comments

Browse files
Files changed (3) hide show
  1. index_large/metadata.json +1 -8
  2. search.py +9 -4
  3. server.py +2 -1
index_large/metadata.json CHANGED
@@ -35,14 +35,7 @@
35
  "mask_punctuation": true,
36
  "checkpoint": "colbert-ir\/colbertv2.0",
37
  "triples": null,
38
- "collection": [
39
- "list with 46880 elements starting with...",
40
- [
41
- "Position paper for YRRSDS 2023",
42
- "In this position paper, I will present the research interests in my PostDoc on safety and robustness specific to conversational AI, including then relevant overlap from my PhD.",
43
- "Speech production is nuanced and unique to every individual, but today{'}s Spoken Dialogue Systems (SDSs) are trained to use general speech patterns to successfully improve performance on various evaluation metrics. However, these patterns do not apply to certain user groups - often the very people that can benefit the most from SDSs. For example, people with dementia produce more disfluent speech than the general population. The healthcare domain is now a popular setting for spoken dialogue and human-robot interaction research. This trend is similar when observing company behaviour. Charities promote industry voice assistants, the creators are getting HIPAA compliance, and their features sometimes target vulnerable user groups. It is therefore critical to adapt SDSs to be more accessible."
44
- ]
45
- ],
46
  "queries": null,
47
  "index_name": "index",
48
  "overwrite": false,
 
35
  "mask_punctuation": true,
36
  "checkpoint": "colbert-ir\/colbertv2.0",
37
  "triples": null,
38
+ "collection": [],
 
 
 
 
 
 
 
39
  "queries": null,
40
  "index_name": "index",
41
  "overwrite": false,
search.py CHANGED
@@ -79,6 +79,10 @@ def init_colbert(index_path=INDEX_PATH, load_index_with_mmap=False):
79
 
80
 
81
  def colbert_score(Q, D_padded, D_mask):
 
 
 
 
82
  assert Q.dim() == 3, Q.size()
83
  assert D_padded.dim() == 3, D_padded.size()
84
  assert Q.size(0) in [1, D_padded.size(0)]
@@ -109,8 +113,7 @@ def generate_candidates(Q):
109
  pids, _ = ivf.lookup(cells)
110
 
111
  # Sort and retun values
112
- sorter = pids.sort()
113
- pids = sorter.values
114
  pids, _ = torch.unique_consecutive(pids, return_counts=True)
115
  return pids, centroid_scores
116
 
@@ -130,11 +133,13 @@ def _calculate_colbert(Q):
130
  # print(ivf_1.shape)
131
  # print(ivf_2.shape)
132
 
133
- # Stage 2 and 3 (Centroid Interaction with Pruning, then without Pruning) - C++ : Filter pids under the centroid score threshold
134
  idx = centroid_scores.max(-1).values >= CENTROID_SCORE_THRESHOLD
135
  pids = filter_pids(
136
  unfiltered_pids, centroid_scores, embeddings.codes, doclens, offsets, idx, NDOCS
137
  )
 
 
138
  # pids_true = IndexScorer.filter_pids(
139
  # unfiltered_pids, centroid_scores, embeddings.codes, doclens, offsets, idx, NDOCS
140
  # )
@@ -150,7 +155,7 @@ def _calculate_colbert(Q):
150
  D_packed = F.normalize(D_packed.to(torch.float32), p=2, dim=-1)
151
  D_mask = doclens[pids.long()]
152
  D_padded, D_lengths = StridedTensor(D_packed, D_mask, use_gpu=False).as_padded_tensor()
153
- print('Stage 3.5 decompression:', pids.shape, '->', D_padded.shape) # (n_docs/4) -> (n_docs/4, decompressed_residuals, hidden_dim)
154
 
155
  # Stage 4 (Final Ranking w/ Decompression) - Calculate the final (expensive) maxsim scores with ColBERT
156
  scores = colbert_score(Q, D_padded, D_lengths)
 
79
 
80
 
81
  def colbert_score(Q, D_padded, D_mask):
82
+ """
83
+ Computes late interaction between question (Q) and documents (D)
84
+ See Figure 1: https://aclanthology.org/2022.naacl-main.272.pdf#page=3
85
+ """
86
  assert Q.dim() == 3, Q.size()
87
  assert D_padded.dim() == 3, D_padded.size()
88
  assert Q.size(0) in [1, D_padded.size(0)]
 
113
  pids, _ = ivf.lookup(cells)
114
 
115
  # Sort and retun values
116
+ pids = pids.sort().values
 
117
  pids, _ = torch.unique_consecutive(pids, return_counts=True)
118
  return pids, centroid_scores
119
 
 
133
  # print(ivf_1.shape)
134
  # print(ivf_2.shape)
135
 
136
+ # Stage 2 and 3 (Centroid Interaction with Pruning, then without Pruning)
137
  idx = centroid_scores.max(-1).values >= CENTROID_SCORE_THRESHOLD
138
  pids = filter_pids(
139
  unfiltered_pids, centroid_scores, embeddings.codes, doclens, offsets, idx, NDOCS
140
  )
141
+
142
+ # C++ : Filter pids under the centroid score threshold
143
  # pids_true = IndexScorer.filter_pids(
144
  # unfiltered_pids, centroid_scores, embeddings.codes, doclens, offsets, idx, NDOCS
145
  # )
 
155
  D_packed = F.normalize(D_packed.to(torch.float32), p=2, dim=-1)
156
  D_mask = doclens[pids.long()]
157
  D_padded, D_lengths = StridedTensor(D_packed, D_mask, use_gpu=False).as_padded_tensor()
158
+ print('Stage 3.5 decompression:', pids.shape, '->', D_padded.shape) # (n_docs/4) -> (n_docs/4, num_toks, hidden_dim)
159
 
160
  # Stage 4 (Final Ranking w/ Decompression) - Calculate the final (expensive) maxsim scores with ColBERT
161
  scores = colbert_score(Q, D_padded, D_lengths)
server.py CHANGED
@@ -67,6 +67,7 @@ if __name__ == "__main__":
67
  http://localhost:8893/api/search?k=25&query=How to extend context windows?
68
  """
69
  init_colbert()
70
- # print(api_search_query("This is a test", 2))
 
71
  print(f'Test it at: http://localhost:8893/api/search?k=25&query=How to extend context windows?')
72
  app.run("0.0.0.0", PORT)
 
67
  http://localhost:8893/api/search?k=25&query=How to extend context windows?
68
  """
69
  init_colbert()
70
+ # test_response = api_search_query("What is NLP?", 2)
71
+ # print(test_response)
72
  print(f'Test it at: http://localhost:8893/api/search?k=25&query=How to extend context windows?')
73
  app.run("0.0.0.0", PORT)