2013-06-12 35 views
1

我使用斯坦福解析器的命令行:斯坦福解析器的處理時間和存儲器消耗

java -mx1500m -cp stanford-parser.jar;stanford-parser-models.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat "penn" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz {file} 

當我在單個句子運行命令與27個即,Java進程正在消耗的100MB內存和解析需要1.5秒。 當我用148個單詞在單個句子上運行命令時,Java進程佔用1.5GB的內存,解析需要1.5分鐘。

我正在使用的機器是Windows 7與英特爾i5 2.53GH。

這些加工時間是否合理? 解析器是否有任何官方性能基準?

+1

(1)給出27個單詞的1.5秒,這聽起來很合理。你會期望可能的解析增加更多,每句更多的話。問題是你爲什麼用148個單詞解析一個句子?自然語言處理可能不是一個很自然的句子。 (2)沒有人喜歡對NLP工具進行基準測試,它體積龐大,除非您執行一些分佈式計算技巧,否則不會是實時的。 – alvas

+0

同意@ 2er0:148可能是一個太長的句子。你能給我們判刑嗎? – Renaud

+0

謝謝,@ 2er0和Renaud。 我想你回答了我的問題。我只是想驗證1.5秒到27個字的句子是否合理,並且我沒有做出完全錯誤的事情。 我同意148個單詞的句子是不合理的。 我解析這麼長的句子的原因是因爲我有一個可以接收任何輸入的系統。 當句子最後沒有用點打斷時,NLP引擎不能正確地分割它們 - 有時候我會得到如此長的句子。 –

回答

2

正如評論,你的問題在於句子分段,因爲你的數據允許任何輸入(有/沒有適當的標點符號)。但不知何故,你有大寫字母很好。因此,您可以嘗試下面的配方,以大寫形式分割句子。

免責聲明:如果你一句I開始,然後在下面的配方沒有什麼幫助=)

「有些事情得改變它必須重新調整我很抱歉,我沒有 意思是傷害我的小女孩它超出了我我無法承載重的世界的重量 所以晚安,晚安,晚安,晚安 晚安,晚安,晚安,晚安,晚安希望 事情運作好所有這麼多的愛,這麼多的學習但我 不會在那裏教你哦,我知道我可以接近但我嘗試我的 最好達到你我很抱歉我並不是故意傷害我的小女孩 女孩它超越了我,我無法承受沉重的世界的重量所以 晚安,晚安,晚安,晚安晚安,晚安,晚安, 晚安,晚安晚安,晚安,晚安晚安, 晚安希望事情順利,yeah謝謝。 「後來

sentence = "Something gotta change It must be rearranged I'm sorry, I did not mean to hurt my little girl It's beyond me I cannot carry the weight of the heavy world So good night, good night, good night, good night Good night, good night, good night, good night, good night Hope that things work out all right So much to love, so much to learn But I won't be there to teach you Oh, I know I can be close But I try my best to reach you I'm so sorry I didn't not mean to hurt my little girl It's beyond me I cannot carry the weight of the heavy world So good night, good night, good night, good night Good night, good night, good night, good night Good night, good night, good night good night, good night Hope that things work out all right, yeah Thank you." 

temp = []; sentences = [] 
for i in sentence.split(): 
    if i[0].isupper() and i != "I": 
     sentences.append(" ".join(temp)) 
     temp = [i] 
    else: 
    temp.append(i) 
sentences.append(" ".join(temp)) 
sentences.pop(0) 
print sentences 

然後,按照這個Stanford Parser and NLTK解析了一句:

在Python中,你可以試試這個細分的句子。