Max margin framework

本文探讨了最大边界解析方法在函数取最大值时的应用,并解释了如何量化反对错误解析的自信度。此外,还介绍了次梯度方法在解决凸优化问题中的作用,特别是在max-margin框架下如何有效应对不可微函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

paper:Max-Margin Parsing

:在函数取最大值的时候,y的取值。(page 2 )

边界的大小利用函数f(x)对w取模,量化了反对错误parse的自信度。

我们希望当错误parse y越来越严重的时候,这个自信度越来越大。

而应用在本文中,应该是

1、当约束条件成立的时候,就是出于支持向量的时候,这个时候距离是最小的。而我们期待的是所有边界之和最大,意味着我们找到了一个最优超平面。

2、当某些离群点处于支持向量和超平面之间是,那么这个时候就会出现边界损失,也就是margin loss。

3、为什么离群点会引起边界损失呢?这是因为离群点会影响支持向量的选取,一旦支持向量选取了离群点,那么最大边界也就会减小。故出现了边界损失。


subgradient:次梯度

经常用在凸优化问题中,我们经常想要求一个函数对某个变量的梯度,但如果这个函数是不可微分的呢。就可以采用次梯度方法

一个函数的次梯度是一个集合[a,b],a表示导数的左极限,b表示导数的右极限,就是这么一个区间的集合。


paper:(Online) Subgradient Methods for Structured Prediction

利用次梯度方法解决max-margin framework的问题


原来风险函数就是松弛变量的一个变形。

约束条件如下:


加入松弛变量后的目标函数:


风险函数r=松弛变量,当等号成立的时候,取得最优解,因此可以让r=松弛变量。

对公式进行变形:




import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @Service public class DeepSeekService { @Autowired private RestTemplate restTemplate; @Autowired private DeepSeekConfig deepSeekConfig; private final ObjectMapper objectMapper = new ObjectMapper(); public String askDeepSeek(String question) throws JsonProcessingException { DeepSeekRequest request = new DeepSeekRequest(); request.setModel("deepseek-chat"); request.setStream(false); List<DeepSeekRequest.Message> messages = List.of( new DeepSeekRequest.Message("user", question) ); request.setMessages(messages); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAuthorization("Bearer " + deepSeekConfig.getApiKey()); HttpEntity<String> entity = new HttpEntity<>(objectMapper.writeValueAsString(request), headers); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(deepSeekConfig.getApiUrl()); ResponseEntity<String> response = restTemplate.postForEntity(builder.toUriString(), entity, String.class); if (response.getStatusCode().is2xxSuccessful()) { DeepSeekResponse deepSeekResponse = objectMapper.readValue(response.getBody(), DeepSeekResponse.class); if (deepSeekResponse != null && deepSeekResponse.getChoices() != null && !deepSeekResponse.getChoices().isEmpty()) { return deepSeekResponse.getChoices().get(0).getDelta().getContent(); } } return "No valid response from DeepSeek"; } } import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.http.ResponseEntity; @RestController public class DeepSeekController { @Autowired private DeepSeekService deepSeekService; @GetMapping("/ask") public ResponseEntity<String> askDeepSeek(@RequestParam String question) { try { String response = deepSeekService.askDeepSeek(question); return ResponseEntity.ok(response); } catch (Exception e) { return ResponseEntity.status(500).body("Error occurred while communicating with DeepSeek: " + e.getMessage()); } } } 根据以上代码帮我生成一个Vue2的deepseek对话页面代码
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值