Skip to content

Commit

Permalink
#4359 Remove deprecated WordVectorSerializer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDBlack committed Feb 21, 2018
1 parent a676772 commit 1eb2c67
Showing 1 changed file with 4 additions and 66 deletions.
Expand Up @@ -22,6 +22,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.compress.compressors.gzip.GzipUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -87,76 +88,13 @@
* @author Adam Gibson
* @author raver119
*/
@Slf4j
public class WordVectorSerializer {
private static final boolean DEFAULT_LINEBREAKS = false;
private static final boolean HAS_HEADER = true;
private static final int MAX_SIZE = 50;
private static final String whitespaceReplacement = "_Az92_";
private static final Logger log = LoggerFactory.getLogger(WordVectorSerializer.class);

private WordVectorSerializer() {}

/**
* Loads the google model
*
* Deprecation note: Please, consider using readWord2VecModel() or loadStaticModel() method instead
*
* @param modelFile
* the path to the google model
* @param binary
* read from binary file format (if set to true) or from text file format.
* @return the loaded model
* @throws IOException
*/
@Deprecated
public static Word2Vec loadGoogleModel(File modelFile, boolean binary) throws IOException {
return loadGoogleModel(modelFile, binary, DEFAULT_LINEBREAKS);
}

/**
* Loads the Google model.
*
* Deprecation note: Please, consider using readWord2VecModel() or loadStaticModel() method instead
*
* @param modelFile
* the input file
* @param binary
* read from binary or text file format
* @param lineBreaks
* if true, the input file is expected to terminate each line with a line break. This
* is typically the case for files created with recent versions of Word2Vec, but not
* for the downloadable model files.
* @return a {@link Word2Vec} object
* @throws IOException
* @author Carsten Schnober
*/
@Deprecated
public static Word2Vec loadGoogleModel(File modelFile, boolean binary, boolean lineBreaks) throws IOException {
return binary ? readBinaryModel(modelFile, lineBreaks, true)
: WordVectorSerializer.fromPair(loadTxt(modelFile));
}

/**
*
* Loads the Google model without normalization being applied.
*
* PLEASE NOTE: Use this method only if you understand why you need not-normalized model. In all other cases please use loadGoogleModel() instead.
*
* Deprecation note: Please, consider using readWord2VecModel() or loadStaticModel() method instead
*
* @param modelFile
* @param binary
* @param lineBreaks
* @return
* @throws IOException
*/
@Deprecated
public static WordVectors loadGoogleModelNonNormalized(File modelFile, boolean binary, boolean lineBreaks)
throws IOException {
return binary ? readBinaryModel(modelFile, lineBreaks, false)
: WordVectorSerializer.fromPair(loadTxt(modelFile));
}

/**
* @param modelFile
* @return
Expand Down Expand Up @@ -2464,7 +2402,7 @@ public static Word2Vec readWord2VecModel(@NonNull File file, boolean extendedMod

Nd4j.getMemoryManager().setOccasionalGcFrequency(originalFreq);

vec = loadGoogleModel(file, true, true);
vec = readBinaryModel(file, true, true);
return vec;
} catch (Exception ey) {
// try to load without linebreaks
Expand All @@ -2474,7 +2412,7 @@ public static Word2Vec readWord2VecModel(@NonNull File file, boolean extendedMod

Nd4j.getMemoryManager().setOccasionalGcFrequency(originalFreq);

vec = loadGoogleModel(file, true, false);
vec = readBinaryModel(file, false, true);
return vec;
} catch (Exception ez) {
throw new RuntimeException(
Expand Down

0 comments on commit 1eb2c67

Please sign in to comment.