protected void backward(DatasetExample example) {
		int size = example.size();

		// Initialize the beta[size-1] values.
		Vector<Double> last = beta.get(size - 1);
		if (tagged[size - 1]) {
			// Zero to every state.
			for (int state = 0; state < numStates; ++state)
				last.set(state, 0.0);

			// Get the correct state.
			int taggedState = example.getFeatureValue(size - 1, stateFeature);
			taggedState = model.featureToState.get(taggedState);

			// Set the correct state probability to one.
			last.set(taggedState, 1.0);
		} else {
			for (int state = 0; state < numStates; ++state)
				last.set(state, 1.0);
		}

		for (int token = size - 2; token >= 0; --token) {
			if (tagged[token]) {
				// Set the probability of every state to zero.
				for (int stateFrom = 0; stateFrom < numStates; ++stateFrom)
					beta.get(token).set(stateFrom, 0.0);

				// Get the correct state.
				int taggedState = example.getFeatureValue(token, stateFeature);
				taggedState = model.featureToState.get(taggedState);

				double betaVal = 0.0;
				int emission = example.getFeatureValue(token + 1,
						observationFeature);

				for (int stateTo = 0; stateTo < numStates; ++stateTo) {
					// Probability of emiting the next symbol.
					double emisProb = model.getEmissionProbability(emission,
							stateTo);

					// Probability of transition.
					double transProb = model.getTransitionProbability(
							taggedState, stateTo);

					betaVal += beta.get(token + 1).get(stateTo) * emisProb
							* transProb;
				}

				// Set the value for the correct state.
				beta.get(token).set(taggedState, betaVal);
			} else {
				for (int stateFrom = 0; stateFrom < numStates; ++stateFrom) {
					double betaVal = 0.0;
					int emission = example.getFeatureValue(token + 1,
							observationFeature);

					for (int stateTo = 0; stateTo < numStates; ++stateTo) {
						// Probability of emiting the next symbol.
						double emisProb = model.getEmissionProbability(
								emission, stateTo);

						// Probability of transition.
						double transProb = model.getTransitionProbability(
								stateFrom, stateTo);

						betaVal += beta.get(token + 1).get(stateTo) * emisProb
								* transProb;
					}

					beta.get(token).set(stateFrom, betaVal);
				}
			}
		}
	}