[英]How to load SR parser file in hdfs in the mapper?
我試圖在mapreduce程序中使用CoreNLP項目來查找存儲在hbase
表中的大量文本的情緒。 我正在使用SR解析器進行解析。 模型文件存儲在hdfs中的/user/root/englishSR.ser.gz
。 我在mapreduce應用程序代碼中添加了以下行
job.addCacheFile(new URI("/user/root/englishSR.ser.gz#model"));
現在在映射器中
props.setProperty("parse.model", "./model");
我收到了edu.stanford.nlp.io.RuntimeIOException: java.io.StreamCorruptedException: invalid stream header
。 pom.xml
文件包含
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.4.1</version>
<classifier>models</classifier>
</dependency>
我已經嘗試將文件添加到resources
並添加到maven
,導致GC overhead limit exceeded
或Java堆問題。
我不太了解hadoop,但我懷疑你對CoreNLP關於SR解析器模型的壓縮感到困惑。
首先嘗試不使用Hadoop:
java -mx4g edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser -serializedPath /user/root/englishSR.ser.gz
看看是否能很好地加載解析器。 如果是這樣,它應該打印類似下面的東西並退出(否則,它將拋出異常......)。
Loading parser from serialized file edu/stanford/nlp/models/srparser/englishSR.ser.gz ... done [10.4 sec].
如果加載解析器很好,那么模型文件沒有任何問題。 我認為問題是CoreNLP只是使用文件或資源名稱是否以“.gz”結尾來決定它是否被gzip壓縮,因此錯誤地解釋了該行:
props.setProperty("parse.model", "./model");
如說要加載一個非壓縮模型。 所以我希望下面的一個或另一個可以工作:
cd /user/root ; gunzip englishSR.ser.gz
job.addCacheFile(new URI("/user/root/englishSR.ser#model"));
props.setProperty("parse.model", "./model");
要么:
job.addCacheFile(new URI("/user/root/englishSR.ser#model.gz"));
props.setProperty("parse.model", "./model.gz");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.