2017-11-15 4 views
1

나와 내 팀은 2 개월 넘게 MS LUIS를 대체하기 위해 Rasa NLU를 사용하고 있으며 지금까지 우리에게 상당히 효과적이었습니다. 이제 약 900 개의 엔트리 동의어가 있습니다 (우리는 LUIS에서 List 엔티티를 사용함).Rasa NLU : 엔티티 동의어 검색 불일치

일부 발화의 경우 엔티티가 동의어로 감지되고 대다수의 발언의 경우 엔티티 동의어를 감지 할 수 없습니다. 동의어를 탐지하기 위해, 나는 단순한 엔티티 라사로 훈련 된 인시던트가 단순하고 동의어 인 것처럼이 인 텐트의 엔티티를 탐지하는 것처럼 보이면 모든 동의어 값을 사용하여 수동으로 다시 훈련하는 또 다른 단순 엔티티를 작성해야합니다.

또 다른 빠른 질문은 일치하는 엔티티 값을 모두 반환하는 LUIS와 달리 하나의 일치 엔티티 만 반환하도록 설계된 Rasa의 엔티티 동의어입니까?

여기에 Rasa에서 LUIS의 엔티티를 나열하는 다른 방법이 있습니까?

답변

1

라사의 엔티티 동의어는 다소 혼동을 줄 수 있습니다. 그들이 제공하는 실제 기능은 매우 간단합니다. 모델에 의해 파싱 된 각 엔티티에 대해 해당 엔티티의 값은 엔티티 동의어 목록과 비교하여 검사됩니다. 값이 엔티티 동의어와 일치하면 동의어 값으로 대체됩니다.

위에서 언급 한 내용 중 큰 부분은으로 대체하기 전에 모델을 모델로 식별해야한다는 것입니다.

간단한 예를 들어 보겠습니다. 여기 내 엔티티 동의어 정의입니다 :

내 훈련 데이터는이 예를 제공하는 경우
{ 
    "value": "New York City", 
    "synonyms": ["NYC", "nyc", "the big apple"] 
} 

: 내 모델이의 실체를 감지 할 수있을 것입니다 수있을 것입니다 매우 가능성이

{ 
    "text": "in the center of NYC", 
    "intent": "search", 
    "entities": [ 
    { 
     "start": 17, 
     "end": 20, 
     "value": "New York City", 
     "entity": "city" 
    } 
    ] 
} 

을 문장은 In the center of the big apple.과 같습니다. 그리고 the big apple이 모델에 의해 엔티티로 구문 분석되지 않으면 뉴욕시를 읽는 엔티티 동의어로 바꿀 수 없습니다.

이런 이유로 실제 common_examples에 엔테이션 라벨이있는 교육 데이터를 추가해야합니다. 엔티티의 모든 변형이 올바르게 분류되면 해당 값을 엔티티 동의어에 추가하면 대체됩니다.

[ 
    { 
    "text": "in the center of NYC", 
    "intent": "search", 
    "entities": [ 
     { 
     "start": 17, 
     "end": 20, 
     "value": "New York City", 
     "entity": "city" 
     } 
    ] 
    }, 
    { 
    "text": "in the centre of New York City", 
    "intent": "search", 
    "entities": [ 
     { 
     "start": 17, 
     "end": 30, 
     "value": "New York City", 
     "entity": "city" 
     } 
    ] 
    } 
] 

나는이 효과에 메모를 추가 할 라사의 문서 페이지에 pull request를 열었습니다.

enter image description here

다음, 나는 라사에 루이스 모델 스키마를 변환하는 샘플 C# 콘솔 응용 프로그램을 작성한 다음 스크린 샷과 같이

+0

답장을 보내 주셔서 감사합니다. 그래서 LUIS의 목록 엔티티 같은 것이 있습니다. 약 900 개의 값을 동의어로 추가 할 수 있습니까? –

+0

우리는 값을 교환하고, 시작/끝 위치를 계산하고, 그것을 'common_examples' 배열에 푸시하는 간단한 스크립트를 사용합니다 (우리는 노드에 있지만, 파이썬 등일 수 있습니다). 'common_examples'에서 인 텐트에 레이블을 지정할 필요가 없다는 점은 주목할 가치가 있습니다. 'text'와'entities'만으로 된 객체를 가지고 있다면 그것은 의도 클래스에 영향을 미치지 않고 엔티티 분류에 영향을줍니다. –

+0

감사합니다, 친구 ... –

0

첫째, 나는이 일을 몇 가지 루이스 모델 JSON을 다운로드 .

다음은 LUISModel 모델 클래스입니다.여기

using Newtonsoft.Json; 
using System; 
using System.Collections.Generic; 

    namespace JSONConversion.Models 
    { 

     public class LuisSchema 
     { 
      public string luis_schema_version { get; set; } 
      public string versionId { get; set; } 
      public string name { get; set; } 
      public string desc { get; set; } 
      public string culture { get; set; } 
      public List<Intent> intents { get; set; } 
      public List<entity> entities { get; set; } 
      public object[] composites { get; set; } 
      public List<Closedlist> closedLists { get; set; } 
      public List<string> bing_entities { get; set; } 
      public object[] actions { get; set; } 
      public List<Model_Features> model_features { get; set; } 
      public List<regex_Features> regex_features { get; set; } 
      public List<Utterance> utterances { get; set; } 
     } 


     public class regex_Features 
     { 
      public string name { get; set; } 
      public string pattern { get; set; } 
      public bool activated { get; set; } 
     } 
     public class Intent 
     { 
      public string name { get; set; } 
     } 

     public class entity 
     { 
      public string name { get; set; } 
     } 

     public class Closedlist 
     { 
      public string name { get; set; } 
      public List<Sublist> subLists { get; set; } 
     } 

     public class Sublist 
     { 
      public string canonicalForm { get; set; } 
      public List<string> list { get; set; } 
     } 

     public class Model_Features 
     { 
      public string name { get; set; } 
      public bool mode { get; set; } 
      public string words { get; set; } 
      public bool activated { get; set; } 
     } 

     public class Utterance 
     { 
      public string text { get; set; } 
      public string intent { get; set; } 

      [JsonProperty("entities")] 
      public List<Entities> Entities { get; set; } 
     } 

     public class Entities 
     { 
      [JsonProperty("entity")] 
      public string Entity { get; set; } 
      public int startPos { get; set; } 
      public int endPos { get; set; } 
     } 
    } 

는 RASAModel 모델 클래스 :

using Newtonsoft.Json; 
using System; 
using System.Collections.Generic; 

namespace JSONConversion.Models 
{ 
    public class RASASchema 
    { 
     public Rasa_Nlu_Data rasa_nlu_data { get; set; } 
    } 

    public class Rasa_Nlu_Data 
    { 
     public List<Entity_Synonyms> entity_synonyms { get; set; } 

     public List<Regex_Features> regex_features { get; set; } 
     public List<Common_Examples> common_examples { get; set; } 

    } 

    public class Entity_Synonyms 
    { 
     public string value { get; set; } 
     public List<string> synonyms { get; set; } 
    } 

    public class Common_Examples 
    { 
     public string text { get; set; } 
     public string intent { get; set; } 
     public List<Entity> entities { get; set; } 
    } 


    public class Entity 
    { 
     public string entity { get; set; } 
     public string value { get; set; } 
     public int start { get; set; } 
     public int end { get; set; } 
    } 

    public class Regex_Features 
    { 
     public string name { get; set; } 
     public string pattern { get; set; } 
    } 
} 

그리고 나는 phraselist 섹션에서 동의어에 대한 LUISModel 모델 클래스를 구문 분석이 방법을 쓴하고 common_examples 객체에 추가합니다 RASA_NLU 훈련 개체에서.

using JSONConversion.Models; 
using Newtonsoft.Json; 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Threading.Tasks; 

namespace JSONConversion.Services 
{ 
    public static class JSONHelper 
    { 
     public static Task<string> ReadFromFile(string FilePath) 
     { 
      try 
      { 
       Task<string> readFromFileTask = Task.Run<string>(() => 
       { 
        return File.ReadAllText(FilePath); 
       }); 
       return readFromFileTask; 
      } 
      catch(Exception ex) 
      { 
       throw; 
      } 
     } 

     public static RASASchema ConvertLUISJSON(string StringifiedLUISJson) 
     { 
      try 
      { 
       LuisSchema luisSchema = JsonConvert.DeserializeObject<LuisSchema>(StringifiedLUISJson); 

       RASASchema rasaSchema = new RASASchema(); 
       rasaSchema.rasa_nlu_data = new Rasa_Nlu_Data(); 
       rasaSchema.rasa_nlu_data.common_examples = new List<Common_Examples>(); 
       rasaSchema.rasa_nlu_data.entity_synonyms = new List<Entity_Synonyms>(); 
       rasaSchema.rasa_nlu_data.regex_features = new List<Regex_Features>(); 


       luisSchema.closedLists.ForEach(x => 
       { 
        x.subLists.ForEach(y => 
        { 
         rasaSchema.rasa_nlu_data.entity_synonyms.Add(new Entity_Synonyms() 
         { 
          value = y.canonicalForm, 
          synonyms = y.list 
         }); 
        }); 
       }); 

       luisSchema.model_features.ForEach(x => 
       { 
        rasaSchema.rasa_nlu_data.entity_synonyms.Add(new Entity_Synonyms() 
        { 
         value = x.name, 
         synonyms = x.words.Split(',').ToList() 
        }); 
       }); 

       luisSchema.regex_features.ForEach(x => 
       { 
        rasaSchema.rasa_nlu_data.regex_features.Add(new Regex_Features() 
        { 
         name = x.name, 
         pattern = x.pattern 
        }); 
       }); 

       luisSchema.utterances.ForEach(x => 
       { 
        Common_Examples rasaUtterances = new Common_Examples(); 
        rasaUtterances.text = x.text; 
        rasaUtterances.intent = x.intent; 

        List<Entity> listOfRASAEntity = new List<Entity>(); 

        x.Entities.ForEach(y => 
        { 
         listOfRASAEntity.Add(new Entity() 
         { 
          start = y.startPos, 
          end = y.endPos, 
          entity = y.Entity, 
          value = x.text.Substring(y.startPos, (y.endPos - y.startPos) + 1) 
         }); 
        }); 

        rasaUtterances.entities = listOfRASAEntity; 
        rasaSchema.rasa_nlu_data.common_examples.Add(rasaUtterances); 
       }); 

       return rasaSchema; 
      } 
      catch (Exception ex) 
      { 
       throw; 
      } 
     } 
    } 
} 

그리고 단지 RASA 모델로 LUIS 모델을 변환하는 JSON 변환 방법을했다.

using System.Text; 
using JSONConversion.Services; 
using System.IO; 
using Newtonsoft.Json; 
using Newtonsoft.Json.Serialization; 

namespace JSONConversion 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      string json = JsonConvert.SerializeObject(JSONConversion.Services.JSONHelper.ConvertLUISJSON(JSONHelper.ReadFromFile(@"C:\Users\xyz\Documents\luis.json").Result), new JsonSerializerSettings() 
      { 
       ContractResolver = new CamelCasePropertyNamesContractResolver(), 
       Formatting = Formatting.Indented 
      }); 

      File.WriteAllText(@"C:\Users\xyz\Desktop\RASA\data\examples\RasaFormat.json", json, Encoding.UTF8); 

     } 
    } 
} 

라사 모델을받은 후, 당신은 단지 동의어 RASA을 훈련 할 수 있습니다.

+0

안녕하세요 @ 답변 감사를 위해 kunal하지만 내 시나리오에서 엔티티 동의어로 약 980 값을 가지고 있고 이미 루아에서 데이터를로드하는 방법을 작성했지만 내 문제는 동의어 탐지의 불일치입니다. –

+0

@Caleb Keller 현재 RASA에 동의어를 공급하는 방법에 주저하고 있습니다. MITIE 파이프 라인은 Windows Server 컴퓨터에 설치되지 않습니다. 어떤 단서가 있다면 알려주세요. 나는 Visual Studio 2015와 함께 Cmake를 사용하여 Git 링크에서 MITIE nlp를 빌드했습니다. 하지만 MITIE 파이프 라인을 Python PyPi 패키지로 통합 할 수는 없습니다. –

+0

@HariGovind RASA에 어떤 종류의 설정을 사용하고 있습니까? Windows 서버 컴퓨터를 사용하고 docker 또는 Ubuntu VM에서 실행하고 있습니까? –

관련 문제