@@ -732,6 +732,67 @@ def predict(
732
732
733
733
return df
734
734
735
+ def score (
736
+ self ,
737
+ X : Union [bpd .DataFrame , bpd .Series ],
738
+ y : Union [bpd .DataFrame , bpd .Series ],
739
+ task_type : Literal [
740
+ "text_generation" , "classification" , "summarization" , "question_answering"
741
+ ] = "text_generation" ,
742
+ ) -> bpd .DataFrame :
743
+ """Calculate evaluation metrics of the model. Only "gemini-pro" model is supported for now.
744
+
745
+ .. note::
746
+
747
+ This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
748
+ Service Specific Terms(https://cloud.google.com/terms/service-terms#1). Pre-GA products and features are available "as is"
749
+ and might have limited support. For more information, see the launch stage descriptions
750
+ (https://cloud.google.com/products#product-launch-stages).
751
+
752
+ .. note::
753
+
754
+ Output matches that of the BigQuery ML.EVALUTE function.
755
+ See: https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-evaluate#remote-model-llm
756
+ for the outputs relevant to this model type.
757
+
758
+ Args:
759
+ X (bigframes.dataframe.DataFrame or bigframes.series.Series):
760
+ A BigQuery DataFrame as evaluation data, which contains only one column of input_text
761
+ that contains the prompt text to use when evaluating the model.
762
+ y (bigframes.dataframe.DataFrame or bigframes.series.Series):
763
+ A BigQuery DataFrame as evaluation labels, which contains only one column of output_text
764
+ that you would expect to be returned by the model.
765
+ task_type (str):
766
+ The type of the task for LLM model. Default to "text_generation".
767
+ Possible values: "text_generation", "classification", "summarization", and "question_answering".
768
+
769
+ Returns:
770
+ bigframes.dataframe.DataFrame: The DataFrame as evaluation result.
771
+ """
772
+ if not self ._bqml_model :
773
+ raise RuntimeError ("A model must be fitted before score" )
774
+
775
+ # TODO(ashleyxu): Support gemini-1.5 when the rollout is ready. b/344891364.
776
+ if self ._bqml_model .model_name .startswith ("gemini-1.5" ):
777
+ raise NotImplementedError ("Score is not supported for gemini-1.5 model." )
778
+
779
+ X , y = utils .convert_to_dataframe (X , y )
780
+
781
+ if len (X .columns ) != 1 or len (y .columns ) != 1 :
782
+ raise ValueError (
783
+ f"Only support one column as input for X and y. { constants .FEEDBACK_LINK } "
784
+ )
785
+
786
+ # BQML identified the column by name
787
+ X_col_label = cast (blocks .Label , X .columns [0 ])
788
+ y_col_label = cast (blocks .Label , y .columns [0 ])
789
+ X = X .rename (columns = {X_col_label : "input_text" })
790
+ y = y .rename (columns = {y_col_label : "output_text" })
791
+
792
+ input_data = X .join (y , how = "outer" )
793
+
794
+ return self ._bqml_model .llm_evaluate (input_data , task_type )
795
+
735
796
def to_gbq (self , model_name : str , replace : bool = False ) -> GeminiTextGenerator :
736
797
"""Save the model to BigQuery.
737
798
0 commit comments