Skip to content
Snippets Groups Projects
Commit 69aeae9c authored by Franck Dary's avatar Franck Dary
Browse files

Added transition set tagparserbt

parent c269c0a0
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ class Transition : ...@@ -14,7 +14,7 @@ class Transition :
if len(splited) == 3 : if len(splited) == 3 :
self.colName = splited[1] self.colName = splited[1]
self.argument = splited[2] self.argument = splited[2]
if not self.name in ["SHIFT","REDUCE","LEFT","RIGHT","BACK","EOS","TAG"] : if not self.name in ["SHIFT","REDUCE","LEFT","RIGHT","BACK","NOBACK","EOS","TAG"] :
raise(Exception("'%s' is not a valid transition type."%name)) raise(Exception("'%s' is not a valid transition type."%name))
def __str__(self) : def __str__(self) :
...@@ -38,6 +38,8 @@ class Transition : ...@@ -38,6 +38,8 @@ class Transition :
applyEOS(config) applyEOS(config)
elif self.name == "TAG" : elif self.name == "TAG" :
applyTag(config, self.colName, self.argument) applyTag(config, self.colName, self.argument)
elif self.name == "NOBACK" :
data = None
elif "BACK" in self.name : elif "BACK" in self.name :
config.historyHistory.add(str([t[0].name for t in config.historyPop])) config.historyHistory.add(str([t[0].name for t in config.historyPop]))
applyBack(config, strategy, self.size) applyBack(config, strategy, self.size)
...@@ -76,6 +78,8 @@ class Transition : ...@@ -76,6 +78,8 @@ class Transition :
return config.wordIndex == len(config.lines) - 1 return config.wordIndex == len(config.lines) - 1
if self.name == "TAG" : if self.name == "TAG" :
return isEmpty(config.getAsFeature(config.wordIndex, self.colName)) return isEmpty(config.getAsFeature(config.wordIndex, self.colName))
if self.name == "NOBACK" :
return True
if "BACK" in self.name : if "BACK" in self.name :
if len(config.historyPop) < self.size : if len(config.historyPop) < self.size :
return False return False
...@@ -95,6 +99,8 @@ class Transition : ...@@ -95,6 +99,8 @@ class Transition :
return scoreOracleReduce(config, missingLinks) return scoreOracleReduce(config, missingLinks)
if self.name == "TAG" : if self.name == "TAG" :
return 0 if self.argument == config.getGold(config.wordIndex, self.colName) else 1 return 0 if self.argument == config.getGold(config.wordIndex, self.colName) else 1
if self.name == "NOBACK" :
return 0
if "BACK" in self.name : if "BACK" in self.name :
return 1 return 1
......
...@@ -52,7 +52,7 @@ if __name__ == "__main__" : ...@@ -52,7 +52,7 @@ if __name__ == "__main__" :
parser.add_argument("--silent", "-s", default=False, action="store_true", parser.add_argument("--silent", "-s", default=False, action="store_true",
help="Don't print advancement infos.") help="Don't print advancement infos.")
parser.add_argument("--transitions", default="eager", parser.add_argument("--transitions", default="eager",
help="Transition set to use (eager | swift | tagparser).") help="Transition set to use (eager | swift | tagparser | tagparserbt).")
parser.add_argument("--ts", default="", parser.add_argument("--ts", default="",
help="Comma separated list of supplementary transitions. Example \"BACK 1,BACK 2\"") help="Comma separated list of supplementary transitions. Example \"BACK 1,BACK 2\"")
parser.add_argument("--network", default="base", parser.add_argument("--network", default="base",
...@@ -93,6 +93,14 @@ if __name__ == "__main__" : ...@@ -93,6 +93,14 @@ if __name__ == "__main__" :
args.predictedStr = "HEAD,UPOS" args.predictedStr = "HEAD,UPOS"
args.states = ["tagger", "parser"] args.states = ["tagger", "parser"]
strategy = {"RIGHT" : (1,0), "SHIFT" : (1,0), "LEFT" : (0,1), "REDUCE" : (0,1), "TAG" : (0,1)} strategy = {"RIGHT" : (1,0), "SHIFT" : (1,0), "LEFT" : (0,1), "REDUCE" : (0,1), "TAG" : (0,1)}
elif args.transitions == "tagparserbt" :
tmpDicts = Dicts()
tmpDicts.readConllu(args.corpus, ["UPOS"], 0)
tagActions = ["TAG UPOS %s"%p for p in tmpDicts.getElementsOf("UPOS") if "__" not in p and not isEmpty(p)]
transitionSets = [[Transition(elem) for elem in tagActions if len(elem) > 0], [Transition(elem) for elem in ["SHIFT","REDUCE","LEFT","RIGHT"] if len(elem) > 0], ["NOBACK","BACK 4"]]
args.predictedStr = "HEAD,UPOS"
args.states = ["tagger", "parser", "backer"]
strategy = {"RIGHT" : (1,2), "SHIFT" : (1,2), "LEFT" : (0,1), "REDUCE" : (0,1), "TAG" : (0,1), "NOBACK" : (0,0)}
elif args.transitions == "swift" : elif args.transitions == "swift" :
transitionSets = [[Transition(elem) for elem in (["SHIFT"]+["LEFT "+str(n) for n in range(1,6)]+["RIGHT "+str(n) for n in range(1,6)]+args.ts.split(',')) if len(elem) > 0]] transitionSets = [[Transition(elem) for elem in (["SHIFT"]+["LEFT "+str(n) for n in range(1,6)]+["RIGHT "+str(n) for n in range(1,6)]+args.ts.split(',')) if len(elem) > 0]]
args.predictedStr = "HEAD" args.predictedStr = "HEAD"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment