CodyBontecou commited on
Commit
b38d2da
·
1 Parent(s): d19a591

output serialization

Browse files
Files changed (1) hide show
  1. handler.py +8 -3
handler.py CHANGED
@@ -36,9 +36,14 @@ class EndpointHandler:
36
  with torch.no_grad():
37
  outputs = self.model(**inputs)
38
 
39
- # Process outputs - this depends on your specific model and requirements
40
- # For now, we'll just return the input as the output to fix the array format issue
41
- return [{"input_text": input_text, "generated_text": outputs}]
 
 
 
 
 
42
 
43
 
44
  if __name__ == "__main__":
 
36
  with torch.no_grad():
37
  outputs = self.model(**inputs)
38
 
39
+ # Process outputs - convert tensors to serializable format
40
+ # Extract the last hidden state and convert to list for JSON serialization
41
+ last_hidden_state = outputs.last_hidden_state
42
+
43
+ # Convert to Python list (serializable) - using the mean of the embeddings as a simple approach
44
+ embedding = last_hidden_state.mean(dim=1).cpu().numpy().tolist()
45
+
46
+ return [{"input_text": input_text, "embedding": embedding}]
47
 
48
 
49
  if __name__ == "__main__":