forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add input/output for custom model (opensearch-project#473)
Signed-off-by: Yaliang Wu <[email protected]> Signed-off-by: Yaliang Wu <[email protected]> Signed-off-by: Sicheng Song <[email protected]>
- Loading branch information
Showing
21 changed files
with
909 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ public enum MLTaskState { | |
RUNNING, | ||
COMPLETED, | ||
FAILED, | ||
CANCELLED | ||
CANCELLED, | ||
COMPLETED_WITH_ERROR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
|
||
public enum MLInputDataType { | ||
SEARCH_QUERY, | ||
DATA_FRAME | ||
DATA_FRAME, | ||
TEXT_DOCS | ||
} |
62 changes: 62 additions & 0 deletions
62
common/src/main/java/org/opensearch/ml/common/dataset/TextDocsInputDataSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataset; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.experimental.FieldDefaults; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.ml.common.annotation.InputDataSet; | ||
import org.opensearch.ml.common.output.model.ModelResultFilter; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) | ||
@InputDataSet(MLInputDataType.TEXT_DOCS) | ||
public class TextDocsInputDataSet extends MLInputDataset{ | ||
|
||
private ModelResultFilter resultFilter; | ||
|
||
private List<String> docs; | ||
|
||
@Builder | ||
public TextDocsInputDataSet(List<String> docs, ModelResultFilter resultFilter) { | ||
super(MLInputDataType.TEXT_DOCS); | ||
this.resultFilter = resultFilter; | ||
Objects.requireNonNull(docs); | ||
if (docs.size() == 0) { | ||
throw new IllegalArgumentException("empty docs"); | ||
} | ||
this.docs = docs; | ||
} | ||
|
||
public TextDocsInputDataSet(StreamInput streamInput) throws IOException { | ||
super(MLInputDataType.TEXT_DOCS); | ||
docs = streamInput.readStringList(); | ||
if (streamInput.readBoolean()) { | ||
resultFilter = new ModelResultFilter(streamInput); | ||
} else { | ||
resultFilter = null; | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
super.writeTo(streamOutput); | ||
streamOutput.writeStringCollection(docs); | ||
if (resultFilter != null) { | ||
streamOutput.writeBoolean(true); | ||
resultFilter.writeTo(streamOutput); | ||
} else { | ||
streamOutput.writeBoolean(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ public enum MLOutputType { | |
TRAINING, | ||
PREDICTION, | ||
SAMPLE_ALGO, | ||
MODEL_TENSOR | ||
} |
63 changes: 63 additions & 0 deletions
63
common/src/main/java/org/opensearch/ml/common/output/model/MLResultDataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.output.model; | ||
|
||
public enum MLResultDataType { | ||
FLOAT32(Format.FLOATING, 4), | ||
FLOAT64(Format.FLOATING, 8), | ||
FLOAT16(Format.FLOATING, 2), | ||
UINT8(Format.UINT, 1), | ||
INT32(Format.INT, 4), | ||
INT8(Format.INT, 1), | ||
INT64(Format.INT, 8), | ||
BOOLEAN(Format.BOOLEAN, 1), | ||
UNKNOWN(Format.UNKNOWN, 0), | ||
STRING(Format.STRING, -1); | ||
|
||
/** The general data type format categories. */ | ||
public enum Format { | ||
FLOATING, | ||
UINT, | ||
INT, | ||
BOOLEAN, | ||
STRING, | ||
UNKNOWN | ||
} | ||
|
||
private Format format; | ||
private int numOfBytes; | ||
|
||
MLResultDataType(Format format, int numOfBytes) { | ||
this.format = format; | ||
this.numOfBytes = numOfBytes; | ||
} | ||
/** | ||
* Checks whether it is a floating data type. | ||
* | ||
* @return whether it is a floating data type | ||
*/ | ||
public boolean isFloating() { | ||
return format == Format.FLOATING; | ||
} | ||
|
||
/** | ||
* Checks whether it is an integer data type. | ||
* | ||
* @return whether it is an integer type | ||
*/ | ||
public boolean isInteger() { | ||
return format == Format.UINT || format == Format.INT; | ||
} | ||
|
||
/** | ||
* Checks whether it is a boolean data type. | ||
* | ||
* @return whether it is a boolean data type | ||
*/ | ||
public boolean isBoolean() { | ||
return format == Format.BOOLEAN; | ||
} | ||
} |
Oops, something went wrong.