kurman commented on a change in pull request #11205: Clojure Contrib Package
URL: https://github.com/apache/incubator-mxnet/pull/11205#discussion_r197869647
 
 

 ##########
 File path: 
contrib/clojure-package/examples/cnn-text-classification/src/cnn_text_classification/classifier.clj
 ##########
 @@ -0,0 +1,112 @@
+;;
+;; Licensed to the Apache Software Foundation (ASF) under one or more
+;; contributor license agreements.  See the NOTICE file distributed with
+;; this work for additional information regarding copyright ownership.
+;; The ASF licenses this file to You under the Apache License, Version 2.0
+;; (the "License"); you may not use this file except in compliance with
+;; the License.  You may obtain a copy of the License at
+;;
+;;    http://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+;;
+
+(ns cnn-text-classification.classifier
+  (:require [cnn-text-classification.data-helper :as data-helper]
+            [org.apache.clojure-mxnet.eval-metric :as eval-metric]
+            [org.apache.clojure-mxnet.io :as mx-io]
+            [org.apache.clojure-mxnet.module :as m]
+            [org.apache.clojure-mxnet.ndarray :as ndarray]
+            [org.apache.clojure-mxnet.optimizer :as optimizer]
+            [org.apache.clojure-mxnet.symbol :as sym]
+            [org.apache.clojure-mxnet.context :as context])
+  (:gen-class))
+
+(def mr-dataset-path "data/mr-data") ;; the MR polarity dataset path
+(def glove-file-path "data/glove/glove.6B.50d.txt")
+
+(defn shuffle-data [test-num {:keys [data label sentence-count sentence-size 
embedding-size]}]
+  (println "Shuffling the data and splitting into training and test sets")
+  (println {:sentence-count sentence-count
+            :sentence-size sentence-size
+            :embedding-size embedding-size})
+  (let [shuffled (shuffle (map (fn [d l] [d l]) data label))
+        train-num (- (count shuffled) test-num)
+        training (into [] (take train-num shuffled))
+        test (into [] (drop train-num shuffled))]
+    {:training {:data  (ndarray/array (into [] (flatten (mapv (fn [v] (first 
v)) training)))
+                                      [train-num 1 sentence-size 
embedding-size]) ;; has to be channel x y
+                :label (ndarray/array (into [] (flatten (mapv (fn [v] (last v) 
) training)))
+                                      [train-num])}
+     :test {:data  (ndarray/array (into [] (flatten (mapv (fn [v] (first v)) 
test)))
+                                  [test-num 1 sentence-size embedding-size]) 
;; has to be channel x y
+            :label (ndarray/array (into [] (flatten (mapv (fn [v] (last v) ) 
test)))
+                                  [test-num])}}))
+
+;;; convnet with multiple filter sizes
+;; from Convolutional Neural Networks for Sentence Classification by Yoon Kim
+(defn get-multi-filter-convnet [num-embed sentence-size batch-size]
+  (let [filter-list [3 4 5]
+        num-filter 100
+        num-label 2
+        dropout 0.5
+        input-x (sym/variable "data")
+        polled-outputs (mapv (fn [filter-size]
+                               (as-> (sym/convolution {:data input-x
 
 Review comment:
   I think the alignment is messed up here, I expect:
   `
   (as->  exp
   
              name
   
              form1
   
              form2)
   `

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to