BaumWelch
baumwelch-0.3.8
OpenGrm-BaumWelch library
Main Page
Namespaces
Classes
Files
File List
File Members
src
grm
baumwelch
baumwelch-0.3.8
src
bin
baumwelchrandomize-main.cc
Go to the documentation of this file.
1
// Licensed under the Apache License, Version 2.0 (the "License");
2
// you may not use this file except in compliance with the License.
3
// You may obtain a copy of the License at
4
//
5
// http://www.apache.org/licenses/LICENSE-2.0
6
//
7
// Unless required by applicable law or agreed to in writing, software
8
// distributed under the License is distributed on an "AS IS" BASIS,
9
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the License for the specific language governing permissions and
11
// limitations under the License.
12
//
13
// Copyright 2017 and onwards Google, Inc.
14
15
// Randomizes model weights.
16
17
#include <cstring>
18
#include <memory>
19
#include <string>
20
21
#include <fst/flags.h>
22
23
#include <fst/script/fst-class.h>
24
#include <fst/script/getters.h>
25
#include <
baumwelch/randomizescript.h
>
26
27
DECLARE_uint64
(seed);
28
29
int
baumwelchrandomize_main
(
int
argc,
char
**argv) {
30
namespace
s =
fst::script
;
31
using
fst::script::MutableFstClass;
32
33
std::string usage =
"Randomizes model weights\n\n Usage: "
;
34
usage += argv[0];
35
usage +=
" [in.fst [out.fst]]\n"
;
36
37
SET_FLAGS(usage.c_str(), &argc, &argv,
true
);
38
39
if
(argc > 3) {
40
ShowUsage();
41
return
1;
42
}
43
44
const
std::string in_name =
45
(argc > 1 && strcmp(argv[1],
"-"
) != 0) ? argv[1] :
""
;
46
const
std::string out_name =
47
(argc > 2 && strcmp(argv[2],
"-"
) != 0) ? argv[2] :
""
;
48
49
std::unique_ptr<MutableFstClass>
fst
(MutableFstClass::Read(in_name,
true
));
50
if
(!fst)
return
1;
51
52
const
auto
seed = s::GetSeed(FST_FLAGS_seed);
53
VLOG(1) << argv[0] <<
": Seed = "
<< seed;
54
55
s::Randomize
(fst.get(), seed);
56
57
return
!fst->Write(out_name);
58
}
59
randomizescript.h
fst
Definition:
a-star.h:30
fst::script
Definition:
decodescript.h:27
baumwelchrandomize_main
int baumwelchrandomize_main(int argc, char **argv)
Definition:
baumwelchrandomize-main.cc:29
fst::Randomize
void Randomize(MutableFst< Arc > *fst, uint64_t seed=std::random_device()())
Definition:
randomize.h:48
DECLARE_uint64
DECLARE_uint64(seed)
Generated by
1.8.11