You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/06/25 15:36:50 UTC
[incubator-nlpcraft] branch NLPCRAFT-70 updated: Weather example
fixed for work with 'geo' profile.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-70
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-70 by this push:
new 751105b Weather example fixed for work with 'geo' profile.
751105b is described below
commit 751105b52ab51f0d0f96a7e690aab0c091fbfbaf
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Thu Jun 25 18:36:42 2020 +0300
Weather example fixed for work with 'geo' profile.
---
.../nlpcraft/server/ctxword/NCContextWordManager.scala | 18 ++++++++----------
.../nlp/enrichers/ctxword/NCContextWordEnricher.scala | 12 ++++++++++--
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/ctxword/NCContextWordManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/ctxword/NCContextWordManager.scala
index 327cbbd..522f2e8 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/ctxword/NCContextWordManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/ctxword/NCContextWordManager.scala
@@ -48,14 +48,12 @@ import scala.util.control.Exception.catching
*
*/
object NCContextWordManager extends NCService with NCOpenCensusServerStats with NCIgniteInstance {
- // Configuration request limit for each processed example.
- private final val CONF_LIMIT = 1000
- // Minimal score for requested words for each processed example.
- private final val CONF_MIN_SCORE = 1
+ private final val CTX_WORDS_LIMIT = 1000
+ private final val CTX_WORDS_MON_SCORE = 1
// If we have a lot of context words candidates, we choose top 50%.
- private final val CONF_TOP_FACTOR = 0.5
+ private final val CTX_WORDS_TOP_FACTOR = 0.5
// If we have small context words candidates count, we choose at least 3.
- private final val CONF_TOP_MIN = 3
+ private final val CTX_WORDS_TOP_MIN = 3
private object Config extends NCConfigurable {
lazy val url: Option[String] = getStringOpt("nlpcraft.server.ctxword.url")
@@ -239,17 +237,17 @@ object NCContextWordManager extends NCService with NCOpenCensusServerStats with
private def getTop[T](seq: Seq[T], getWeight: T ⇒ Double): Seq[T] = {
require(seq.nonEmpty)
- require(CONF_TOP_FACTOR > 0 && CONF_TOP_FACTOR < 1)
+ require(CTX_WORDS_TOP_FACTOR > 0 && CTX_WORDS_TOP_FACTOR < 1)
val seqW = seq.map(p ⇒ p → getWeight(p)).sortBy(-_._2)
- val limitSum = seqW.map { case (_, factor) ⇒ factor }.sum * CONF_TOP_FACTOR
+ val limitSum = seqW.map { case (_, factor) ⇒ factor }.sum * CTX_WORDS_TOP_FACTOR
val v = new AtomicDouble(0)
val top = for ((value, factor) ← seqW if v.getAndAdd(factor) < limitSum) yield value
- if (top.size < CONF_TOP_MIN) seqW.take(CONF_TOP_MIN).map { case (value, _) ⇒ value } else top
+ if (top.size < CTX_WORDS_TOP_MIN) seqW.take(CTX_WORDS_TOP_MIN).map { case (value, _) ⇒ value } else top
}
@throws[NCE]
@@ -298,7 +296,7 @@ object NCContextWordManager extends NCService with NCOpenCensusServerStats with
val allResp = suggest(
allReqs.map(_.request),
- NCContextWordParameter(limit = CONF_LIMIT, totalScore = CONF_MIN_SCORE)
+ NCContextWordParameter(limit = CTX_WORDS_LIMIT, totalScore = CTX_WORDS_MON_SCORE)
)
require(allResp.size == allReqs.size)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
index e3a9cf2..397b39e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/nlp/enrichers/ctxword/NCContextWordEnricher.scala
@@ -33,6 +33,8 @@ object NCContextWordEnricher extends NCServerEnricher {
private final val POS_PLURALS = Set("NNS", "NNPS")
private final val POS_SINGULAR = Set("NN", "NNP")
+ private final val CTX_WORDS_LIMIT = 1000
+
private case class Word(text: String, index: Int, examplePos: String, wordPos: String)
private case class Holder(
elementId: String,
@@ -89,7 +91,12 @@ object NCContextWordEnricher extends NCServerEnricher {
val suggs =
NCContextWordManager.suggest(
toks.map(t ⇒ NCContextWordRequest(words, t.index)),
- NCContextWordParameter(totalScore = f.getMinTotalSentence, ftextScore = f.getMinTotalExample)
+ NCContextWordParameter(
+ limit = CTX_WORDS_LIMIT,
+ totalScore = f.getMinTotalSentence,
+ ftextScore = f.getMinTotalExample
+
+ )
)
require(toks.size == suggs.size)
@@ -142,7 +149,8 @@ object NCContextWordEnricher extends NCServerEnricher {
val allSuggs =
NCContextWordManager.suggest(
allReqs.flatMap(_.requests),
- NCContextWordParameter(totalScore = f.getMinTotalExample, ftextScore = f.getMinFtextExample / 2) // TODO:
+ // Ftext factor - used default.
+ NCContextWordParameter(limit = CTX_WORDS_LIMIT, totalScore = f.getMinTotalExample)
)
require(allSuggs.size == allReqs.map(_.requests.size).sum)