Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update embedding tag #422

Merged
merged 7 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions frontend/src/high-dimensional/HighDimensional.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="visual-dl-page-right">
<div class="visual-dl-page-config-container">
<ui-config
:runs-items="runsItems"
:config="config"
/>
</div>
Expand All @@ -20,7 +21,7 @@
</template>

<script>
import {getHighDimensionalDatasets} from '../service';
import {getHighDimensionalDatasets, getRuns} from '../service';
import autoAdjustHeight from '../common/util/autoAdjustHeight';
import Config from './ui/Config';
import Chart from './ui/Chart';
Expand All @@ -33,18 +34,27 @@ export default {
name: 'HighDimensional',
data() {
return {
runsArray: [],
config: {
searchText: '',
displayWordLabel: true,
dimension: '2',
reduction: 'tsne',
showingRun: '',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a better name? 'showingRun' is quite confusing 😢

Copy link
Collaborator Author

@jetfuel jetfuel Apr 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, any suggestion? currentRun?

running: true,
},
embeddingData: [],
};
},
created() {
this.fetchDatasets();
getRuns().then(({errno, data}) => {
this.runsArray = data;

// Setting showingRun should trigger fetchDatasets
if (data.length > 0) {
this.config.showingRun = data[0];
}
});
},
watch: {
'config.dimension': function(val) {
Expand All @@ -53,16 +63,31 @@ export default {
'config.reduction': function(val) {
this.fetchDatasets();
},
'config.showingRun': function(val) {
this.fetchDatasets();
},
},
mounted() {
autoAdjustHeight();
},
computed: {
runsItems() {
let runsArray = this.runsArray || [];
return runsArray.map((item) => {
return {
name: item,
value: item,
};
});
},
},
methods: {
fetchDatasets() {
// Fetch the data from the server. Passing dimension and reduction method
let params = {
dimension: this.config.dimension,
reduction: this.config.reduction,
run: this.config.showingRun,
};
getHighDimensionalDatasets(params).then(({errno, data}) => {
let vectorData = data.embedding;
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/high-dimensional/ui/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
value="pca"/>
</v-radio-group>

<v-radio-group
label="Run"
v-model="config.showingRun"
dark>
<v-radio
v-for="item in runsItems"
:key="item.name"
:label="item.name"
:value="item.value" />
</v-radio-group>

<v-btn
:color="config.running ? 'primary' : 'error'"
v-model="config.running"
Expand All @@ -55,6 +66,10 @@

export default {
props: {
runsItems: {
type: Array,
required: true,
},
config: {
type: Object,
required: true,
Expand Down
12 changes: 6 additions & 6 deletions visualdl/python/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
from visualdl import core

dtypes = ("float", "double", "int32", "int64")
EMBEDDING_TAG = 'embedding'


def check_tag_name_valid(tag):
assert '%' not in tag, "character % is a reserved word, it is not allowed in tag."
assert tag != EMBEDDING_TAG, "embedding is a reserved word, it is not allowed in tag."


def check_mode_name_valid(tag):
Expand Down Expand Up @@ -140,9 +142,8 @@ def text(self, tag):
check_tag_name_valid(tag)
return self.reader.get_text(tag)

def embedding(self, tag):
check_tag_name_valid(tag)
return self.reader.get_embedding(tag)
def embedding(self):
return self.reader.get_embedding(EMBEDDING_TAG)

def audio(self, tag):
"""
Expand Down Expand Up @@ -290,9 +291,8 @@ def text(self, tag):
check_tag_name_valid(tag)
return self.writer.new_text(tag)

def embedding(self, tag):
check_tag_name_valid(tag)
return self.writer.new_embedding(tag)
def embedding(self):
return self.writer.new_embedding(EMBEDDING_TAG)

def save(self):
self.writer.save()
Expand Down
9 changes: 2 additions & 7 deletions visualdl/server/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,9 @@ def get_texts(storage, mode, tag, num_records=100):
return res


def get_embeddings(storage,
mode,
tag,
reduction,
dimension=2,
num_records=5000):
def get_embeddings(storage, mode, reduction, dimension=2, num_records=5000):
with storage.mode(mode) as reader:
embedding = reader.embedding(tag)
embedding = reader.embedding()
labels = embedding.get_all_labels()
high_dimensional_vectors = embedding.get_all_embeddings()

Expand Down
5 changes: 3 additions & 2 deletions visualdl/server/visualDL
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ def texts():

@app.route('/data/plugin/embeddings/embeddings')
def embeddings():
run = request.args.get('run')
dimension = request.args.get('dimension')
reduction = request.args.get('reduction')
key = os.path.join('/data/plugin/embeddings/embeddings', dimension, reduction)
data = cache_get(key, try_call, lib.get_embeddings, log_reader, 'train', 'scratch/embedding', reduction, int(dimension))
key = os.path.join('/data/plugin/embeddings/embeddings', run, dimension, reduction)
data = cache_get(key, try_call, lib.get_embeddings, log_reader, run, reduction, int(dimension))
result = gen_result(0, "", data)
return Response(json.dumps(result), mimetype='application/json')

Expand Down