MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / Train

Function Train

go/codegen/tensorflow/codegen.go:257–301  ·  view source on GitHub ↗

Train generates a Python program for train a TensorFlow model.

(trainStmt *ir.TrainStmt, session *pb.Session)

Source from the content-addressed store, hash-verified

255
256// Train generates a Python program for train a TensorFlow model.
257func Train(trainStmt *ir.TrainStmt, session *pb.Session) (string, error) {
258 trainParams, validateParams, modelParams := CategorizeAttributes(trainStmt)
259 featureColumnsCode, fieldDescs, err := DeriveFeatureColumnCodeAndFieldDescs(trainStmt)
260 if err != nil {
261 return "", err
262 }
263
264 // Need to create tmp table for train/validate when using PAI
265 paiTrainTable := ""
266 paiValidateTable := ""
267 if IsPAI() && trainStmt.TmpTrainTable != "" {
268 paiTrainTable = trainStmt.TmpTrainTable
269 paiValidateTable = trainStmt.TmpValidateTable
270 }
271
272 filler := trainFiller{
273 DataSource: session.DbConnStr,
274 TrainSelect: trainStmt.Select,
275 ValidationSelect: trainStmt.ValidationSelect,
276 Estimator: trainStmt.Estimator,
277 FieldDescs: fieldDescs,
278 FeatureColumnCode: fmt.Sprintf("{%s}", strings.Join(featureColumnsCode, ",\n")),
279 Y: trainStmt.Label.GetFieldDesc()[0], // TODO(typhoonzero): label only support numericColumn.
280 ModelParams: modelParams,
281 TrainParams: trainParams,
282 ValidationParams: validateParams,
283 Save: "model_save",
284 LoadPreTrainedModel: trainStmt.PreTrainedModel != "",
285 IsPAI: IsPAI(),
286 PAITrainTable: paiTrainTable,
287 PAIValidateTable: paiValidateTable,
288 ModelRepoImage: trainStmt.ModelImage,
289 OriginalSQL: trainStmt.OriginalSQL,
290 }
291 var program bytes.Buffer
292 var trainTemplate = template.Must(template.New("Train").Funcs(template.FuncMap{
293 "intArrayToJSONString": ir.MarshalToJSONString,
294 "attrToPythonValue": ir.AttrToPythonValue,
295 "DTypeToString": ir.DTypeToString,
296 }).Parse(tfTrainTemplateText))
297 if err := trainTemplate.Execute(&program, filler); err != nil {
298 return "", err
299 }
300 return program.String(), nil
301}
302
303// Pred generates a Python program for predict using a TensorFlow model.
304func Pred(predStmt *ir.PredictStmt, session *pb.Session) (string, error) {

Callers 6

ExecuteTrainMethod · 0.92
TestTrainCodegenFunction · 0.92
TFTrainWithLoadAndSaveFunction · 0.92
TestTrainCodegenFunction · 0.70
TestTrainWithOptimizerFunction · 0.70

Calls 6

CategorizeAttributesFunction · 0.85
IsPAIFunction · 0.85
GetFieldDescMethod · 0.65
ParseMethod · 0.65
StringMethod · 0.45

Tested by 4

TestTrainCodegenFunction · 0.74
TestTrainCodegenFunction · 0.56
TestTrainWithOptimizerFunction · 0.56