Пример #1
0
func predict(c ntm.Controller, shi [][]string, gen *poem.Generator) [][]float64 {
	machine := ntm.MakeEmptyNTM(c)

	// Feed the poem constraints into the NTM.
	numChar := 0
	output := make([][]float64, 0)
	for _, line := range shi {
		for _, s := range line {
			numChar += 1
			input := vecFromString(s, gen)
			machine, output = forward(machine, input, output)
		}
		numChar += 1
		input := gen.Linefeed()
		machine, output = forward(machine, input, output)
	}
	input := gen.EndOfPoem()
	machine, output = forward(machine, input, output)

	input = make([]float64, gen.InputSize())
	machine, output = forward(machine, input, output)

	// Follow the predictions of the NTM.
	i := 1
	for _, line := range shi {
		for _, s := range line {
			if s != "" {
				input = vecFromString(s, gen)
			} else {
				input, _ = sample(output[len(output)-1], gen)
			}
			machine, output = forward(machine, input, output)
			i++
		}

		if i >= numChar {
			break
		}
		input, _ = sample(output[len(output)-1], gen)
		machine, output = forward(machine, input, output)
		i++
	}

	return output
}