feat: 增加rlhf排序的基础逻辑

This commit is contained in:
maxmon 2023-04-13 01:51:14 +08:00
parent 9f9b3db46c
commit 9cf736ba33
3 changed files with 137 additions and 3 deletions

View File

@ -109,6 +109,7 @@
</template>
</div>
<CVPoint v-if="projectType === '图片点标注'" :fileContent="nowText" :annoDetails="ners" :nowType="nowType" :types="types" :save="save"></CVPoint>
<RLHF v-if="projectType === '人类反馈强化学习'" :fileContent="nowText" :annoDetails="ners" :nowType="nowType" :types="types" :save="save"></RLHF>
</div>
<div class="page-btn-box">
<button class="page-btn" @click="changeIdx(-1, $event)" @mouseover="setFocus('page-up')" @mouseleave="setFocus('')">上一个 {{ fastTypeKey['page-up'] ? `${fastTypeKey['page-up']}` : '' }}</button>
@ -135,6 +136,7 @@
import { getColor } from '../../js/color.js'
import { saveAsFile } from '../../js/utils.js'
import CVPoint from '@/components/CV/point.vue'
import RLHF from '@/components/NLP/rlhf.vue'
//
const isLocal = false
@ -190,7 +192,8 @@ function updateType2Server (projectName, typeList, types) {
export default {
name: 'NER',
components: {
CVPoint
CVPoint,
RLHF
},
data () {
return {
@ -433,6 +436,13 @@ export default {
}
this.$set(this, 'nowType', type)
this.save()
} else if (this.projectType === '人类反馈强化学习') {
console.log(this.nowText === type, type)
this.$set(this, 'nowType', type)
clearInterval(window.rlhf_inter)
window.rlhf_inter = setInterval(() => {
this.$set(this, 'nowType', '')
}, 200)
} else {
console.log(type)
this.$set(this, 'nowType', type)
@ -740,8 +750,8 @@ export default {
return entityType.type
})
that.types = types
//
if (that.typeList && that.typeList[0] && projectType.indexOf('分类') === -1) that.nowType = that.typeList[0]
//
if (that.typeList && that.typeList[0] && projectType.indexOf('分类') === -1 && projectType.indexOf('强化学习') === -1) that.nowType = that.typeList[0]
that.getFiles()
}
function calcColumnWordCount () {

View File

@ -0,0 +1,123 @@
<template>
<div class="rlhf-box">
<div v-for="(line, idx) in fileContent.split('\n')" :key="idx" class="line" @click="clickLine(idx)">
<template v-for="(word, idx) in line">
<span class="word" v-if="word !== '\n'" :key="idx">{{ word }}</span>
<br v-if="word === '\n'" :key="idx"/>
</template>
<span class="rank" v-if="annoDetails.indexOf(String(idx+1)) !== -1">{{annoDetails.indexOf(String(idx+1)) + 1}}</span>
</div>
</div>
</template>
<script>
export default ({
name: 'RLHF',
props: {
fileContent: {
type: String,
default: '',
required: true
},
annoDetails: {
type: Array,
default: () => [],
required: true
},
nowType: {
type: String,
default: '1234',
required: true
},
types: {
type: Object,
default: () => {},
required: true
},
save: {
type: Function,
required: true
}
},
data () {
return {
points: [],
width: 0,
height: 0
}
},
methods: {
log (...args) {
console.log(args)
},
clickLine (idx) {
let rank = String(idx + 1)
if (this.annoDetails.indexOf(rank) === -1) {
this.annoDetails.push(rank)
} else {
this.annoDetails.splice(this.annoDetails.indexOf(rank), 1)
}
this.save()
}
},
watch: {
annoDetails: {
handler (val) {
console.log(val)
},
deep: true
},
nowType: {
handler (val) {
if (!val) {
return
}
if (this.annoDetails.indexOf(val) === -1) {
this.annoDetails.push(val)
} else {
this.annoDetails.splice(this.annoDetails.indexOf(val), 1)
}
this.save()
}
}
}
})
</script>
<style scoped>
.rlhf-box {
display: flex;
flex-direction: column;
}
.line {
position: relative;
border-bottom: 1px solid;
height: 36px;
}
.line:hover {
background-color: #eee;
}
.line>.rank {
position: absolute;
right: 4px;
top: 0;
bottom: 0;
font-size: 36px;
line-height: 36px;
margin: auto;
}
.word {
display: inline-block;
position: relative;
padding-bottom: 15px;
width: 20px;
height: 20px;
line-height: 20px;
vertical-align: bottom;
box-sizing: content-box;
text-align: center;
font-size: 16px;
z-index: 4;
}
</style>

View File

@ -28,6 +28,7 @@
<option value ="命名实体识别">命名实体识别</option>
<option value ="文本分类">文本分类</option>
<option value ="图片点标注">图片点标注</option>
<option value ="人类反馈强化学习">人类反馈强化学习</option>
</select>
</p>
<div class="title">