INNER CODE UNIT · Go

sum

mb-14/gomarkov · gomarkov.go:117

	sum := float64(arr.sum())
	freq := float64(arr[nextIndex])
	return freq / sum, nil
}

// Generate generates new text based on an initial seed of words
func (chain *Chain) Generate(current NGram) (string, error) {
	return chain.GenerateDeterministic(current, defaultPrng)
}

// GenerateDeterministic generates new text deterministically, based on an initial seed of words and using a specified PRNG.
// Use it for reproducibly pseudo-random results (i.e. pass the same PRNG and same state every time).
func (chain *Chain) GenerateDeterministic(current NGram, prng PRNG) (string, error) {
	if len(current) != chain.Order {
		return "", errors.New("N-gram length does not match chain order")
	}
	if current[len(current)-1] == EndToken {
		// Dont generate anything after the end token

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…