public double GetFeatureValue(string t2, string t1, string t, int pos, bool debug, out string debugStr) { var features = new Features(t2, t1, t, _sentence, pos); double sum = 0; debugStr = "@@"; foreach (var feature in features.GetFeatures()) { var weight = WeightVector.Get(feature); sum += weight; if (debug) { debugStr += feature + "#" + weight.ToString(CultureInfo.InvariantCulture) + "%%"; } } debugStr += "@@"; if (_crf) { var val = Math.Exp(sum); if (double.IsInfinity(val)) { return sum; } return val; } return sum; }
public double GetFeatureK(string prevTag, string tag, int pos, int k, List<string> line) { var features = new Features("*", prevTag, tag, line, pos); foreach (var feature in features.GetFeatures()) { if (WeightVector.GetFeatureToK(feature) == k) { return Math.Exp(WeightVector.Get(k)); } } return 0; }
public static void TestMethod1() { var str = new List<string> { "You", "leave", "the", "Nagpur-Jabbalpur", "highway", "at", "Pawni", "and", "proceed", "to", "Sillari." }; var ft = new Features("OTHER", "OTHER", "LOCATION", str, 6); foreach (var feat in ft.GetFeatures()) { Console.WriteLine(feat); } }
public IEnumerable<KeyValuePair<string, string>> NextFeature() { string t2 = "*", t1 = "*"; for (; _pos < _sentence.Count; _pos++) { var t = _tags[_pos]; if (_pos > 1) { t2 = _tags[_pos - 2]; t1 = _tags[_pos - 1]; } else if (_pos == 1) { t1 = _tags[_pos - 1]; } var features = new Features(t2, t1, t, _sentence, _pos); foreach (var f in features.GetFeatures()) { var pair = new KeyValuePair<string, string>(t, f); yield return pair; } } }
private void StoreFeature(string prevTag, string tag, int pos, int lineIndex) { var features = new Features("*", prevTag, tag, Sentences[lineIndex], pos); foreach (var feature in features.GetFeatures()) { int k = _featureTokDictionary[feature]; Cache[lineIndex][pos].Add(string.Format("{0}@#{1}@#{2}", prevTag, tag, k.ToString(CultureInfo.InvariantCulture))); } }
private void GenerateFeatures(string temp, List<string> inputSentance, int pos) { var tags = temp.Split(new char[] { ':' }); if (tags.Length != 3) { throw new Exception(temp + " doesn't contain 3 tags"); } var features = new Features(tags[0], tags[1], tags[2], inputSentance, pos); foreach (var feature in features.GetFeatures()) { if (DictFeaturesToK.ContainsKey(feature)) continue; DictFeaturesToK.Add(feature, FeatureCount); DictKToFeatures.Add(FeatureCount, feature); FeatureCount++; } }