-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathWordSegCommand.swift
84 lines (65 loc) · 2.37 KB
/
WordSegCommand.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2020 The TensorFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import ArgumentParser
struct WordSegCommand: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "WordSeg",
abstract: """
Runs training for the WordSeg model.
"""
)
@Flag(help: "Use eager backend (default).")
var eager: Bool = false
@Flag(help: "Use X10 backend.")
var x10: Bool = false
@Option(help: "Path to training data.")
var trainingPath: String?
@Option(help: "Path to validation data.")
var validationPath: String?
@Option(help: "Path to test data.")
var testPath: String?
@Option(help: "Maximum number of training epochs.")
var maxEpochs: Int = 1000
@Option(help: "Size of hidden layers.")
var hiddenSize: Int = 512
@Option(help: "Dropout rate.")
var dropoutProbability: Double = 0.5
@Option(help: "Power of the length penalty.")
var order: Int = 5
@Option(help: "Initial learning rate.")
var learningRate: Float = 0.001
@Option(help: "Weight of the length penalty.")
var lambd: Float = 0.00075
@Option(help: "Maximum length of a word.")
var maxLength: Int = 10
@Option(help: "Minimum frequency of a word.")
var minFrequency: Int = 10
func validate() throws {
guard !(eager && x10) else {
throw ValidationError(
"Can't specify both --eager and --x10 backends.")
}
}
func run() throws {
let backend: Backend = x10 ? .x10 : .eager
let settings = WordSegSettings(
trainingPath: trainingPath,
validationPath: validationPath, testPath: testPath,
hiddenSize: hiddenSize, dropoutProbability: dropoutProbability,
order: order, lambd: lambd, maxEpochs: maxEpochs,
learningRate: learningRate, backend: backend,
maxLength: maxLength, minFrequency: minFrequency)
try runTraining(settings: settings)
}
}