-
Notifications
You must be signed in to change notification settings - Fork 253
Open
Description
We have finetuned the paraphrase-mpnet-base-v2 using setfit 1.0.3 and I have upgraded the setfit ==1.1.2 when I load the model it is throwing me the error
AttributeError: 'SentenceTransformer' object has no attribute 'default_prompt_name'
Code:
with open('v1.pkl', 'rb') as f:
model = pickle.load(f)
def predict_proba(texts, model):
return model.predict_proba(texts)
# Predicting top 3 probabilities
test_df['predicted_probas'] = test_df.apply(
lambda x: pd.Series(predict_proba([x.Text], model)[0]).nlargest(3).values.tolist(),
axis=1
)
Full trace:
AttributeError: 'SentenceTransformer' object has no attribute 'default_prompt_name'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File <command-8842824531215917>, line 7
4 return model.predict_proba(texts)
6 # Predicting top 3 probabilities
----> 7 test_df['predicted_probas'] = test_df.apply(
8 lambda x: pd.Series(predict_proba([x.Text], model)[0]).nlargest(3).values.tolist(),
9 axis=1
10 )
File /databricks/python/lib/python3.10/site-packages/pandas/core/frame.py:8848, in DataFrame.apply(self, func, axis, raw, result_type, args, **kwargs)
8837 from pandas.core.apply import frame_apply
8839 op = frame_apply(
8840 self,
8841 func=func,
(...)
8846 kwargs=kwargs,
8847 )
-> 8848 return op.apply().__finalize__(self, method="apply")
File /databricks/python/lib/python3.10/site-packages/pandas/core/apply.py:733, in FrameApply.apply(self)
730 elif self.raw:
731 return self.apply_raw()
--> 733 return self.apply_standard()
File /databricks/python/lib/python3.10/site-packages/pandas/core/apply.py:857, in FrameApply.apply_standard(self)
856 def apply_standard(self):
--> 857 results, res_index = self.apply_series_generator()
859 # wrap results
860 return self.wrap_results(results, res_index)
File /databricks/python/lib/python3.10/site-packages/pandas/core/apply.py:873, in FrameApply.apply_series_generator(self)
870 with option_context("mode.chained_assignment", None):
871 for i, v in enumerate(series_gen):
872 # ignore SettingWithCopy here in case the user mutates
--> 873 results[i] = self.f(v)
874 if isinstance(results[i], ABCSeries):
875 # If we have a view on v, we need to make a copy because
876 # series_generator will swap out the underlying data
877 results[i] = results[i].copy(deep=False)
File <command-8842824531215917>, line 8, in <lambda>(x)
4 return model.predict_proba(texts)
6 # Predicting top 3 probabilities
7 test_df['predicted_probas'] = test_df.apply(
----> 8 lambda x: pd.Series(predict_proba([x.Text], model)[0]).nlargest(3).values.tolist(),
9 axis=1
10 )
File <command-8842824531215917>, line 4, in predict_proba(texts, model)
2 def predict_proba(texts, model):
3 # Assuming model has a method predict_proba
----> 4 return model.predict_proba(texts)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-f8054330-4852-4683-b8e1-f27677fba16f/lib/python3.10/site-packages/setfit/modeling.py:514, in SetFitModel.predict_proba(self, inputs, batch_size, as_numpy, show_progress_bar)
512 if is_singular:
513 inputs = [inputs]
--> 514 embeddings = self.encode(inputs, batch_size=batch_size, show_progress_bar=show_progress_bar)
515 probs = self.model_head.predict_proba(embeddings)
516 if isinstance(probs, list):
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-f8054330-4852-4683-b8e1-f27677fba16f/lib/python3.10/site-packages/setfit/modeling.py:451, in SetFitModel.encode(self, inputs, batch_size, show_progress_bar)
436 def encode(
437 self, inputs: List[str], batch_size: int = 32, show_progress_bar: Optional[bool] = None
438 ) -> Union[torch.Tensor, np.ndarray]:
439 """Convert input sentences to embeddings using the `SentenceTransformer` body.
440
441 Args:
(...)
449 torch Tensor if this model has a differentiable Torch head, or otherwise as a numpy array.
450 """
--> 451 return self.model_body.encode(
452 inputs,
453 batch_size=batch_size,
454 normalize_embeddings=self.normalize_embeddings,
455 convert_to_tensor=self.has_differentiable_head,
456 show_progress_bar=show_progress_bar,
457 )
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-f8054330-4852-4683-b8e1-f27677fba16f/lib/python3.10/site-packages/torch/utils/_contextlib.py:116, in context_decorator.<locals>.decorate_context(*args, **kwargs)
113 @functools.wraps(func)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-f8054330-4852-4683-b8e1-f27677fba16f/lib/python3.10/site-packages/sentence_transformers/SentenceTransformer.py:987, in SentenceTransformer.encode(self, sentences, prompt_name, prompt, batch_size, show_progress_bar, output_value, precision, convert_to_numpy, convert_to_tensor, device, normalize_embeddings, truncate_dim, pool, chunk_size, **kwargs)
983 except KeyError:
984 raise ValueError(
985 f"Prompt name '{prompt_name}' not found in the configured prompts dictionary with keys {list(self.prompts.keys())!r}."
986 )
--> 987 elif self.default_prompt_name is not None:
988 prompt = self.prompts.get(self.default_prompt_name, None)
989 else:
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-f8054330-4852-4683-b8e1-f27677fba16f/lib/python3.10/site-packages/torch/nn/modules/module.py:1940, in Module.__getattr__(self, name)
1938 if name in modules:
1939 return modules[name]
-> 1940 raise AttributeError(
1941 f"'{type(self).__name__}' object has no attribute '{name}'"
1942 )
AttributeError: 'SentenceTransformer' object has no attribute 'default_prompt_na
Metadata
Metadata
Assignees
Labels
No labels