我在尝试启动 Spring Boot 应用程序时遇到此错误,但我似乎无法弄清楚原因。任何帮助都受到高度赞赏。
org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]中定义名为“springSecurityFilterChain”的bean创建错误:通过工厂方法的Bean实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [javax.servlet.Filter]:工厂方法“springSecurityFilterChain”抛出异常;嵌套异常是 java.lang.IllegalStateException: Can't configure anyRequest after its own
在 super.configure(http) 方法中失败。这是我的“SpringSecurityConfig.java”类
@Configuration
@EnableWebSecurity(debug = true)
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomUserDetailService customUserDetailsService;
@Bean
public JWTAuthenticationFilter jwtAuthenticationFilter() {
return new JWTAuthenticationFilter();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/auth/**").permitAll()
.anyRequest()
.authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
super.configure(http);
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Huggingface Transformers 库-pytorch 微调用于语言生成任务的 GPT-2 模型,并且我需要计算微调模型的评估分数(困惑度)。但我不确定如何使用损失来做到这一点。我想知道如何使用 sum_loss 或平均损失来计算模型的困惑度,也欢迎任何其他建议。任何帮助都是appriced。
编辑:
outputs = model(article_tens, labels=article_tens)
loss, prediction_scores = outputs[:2]
loss.backward()
sum_loss = sum_loss + loss.detach().data
Run Code Online (Sandbox Code Playgroud)
上面给出的是我如何计算微调任务的每批数据的损失。
sum loss 1529.43408203125
loss 4.632936000823975
prediction_scores tensor([[[-11.2291, -9.2614, -11.8575, ..., -18.1927, -17.7286, -11.9215],
[-67.2786, -63.5928, -70.7110, ..., -75.3516, -73.8672, -67.6637],
[-81.1397, -80.0295, -82.9357, ..., -83.7913, -85.7201, -78.9877],
...,
[-85.3213, -82.5135, -86.5459, ..., -90.9160, -90.4393, -82.3141],
[-44.2260, -43.1702, -49.2296, ..., -58.9839, -55.2058, -42.3312],
[-63.2842, -59.7334, -61.8444, ..., -75.0798, -75.7507, -54.0160]]],
device='cuda:0', grad_fn=<UnsafeViewBackward>)
Run Code Online (Sandbox Code Playgroud)
上面给出的是仅打印批次的损失时的情况
我正在微调语言模型,并计算训练和验证损失以及训练和验证困惑度。在我的程序中,它是通过损失的指数来计算的。我知道较低的困惑度代表更好的语言模型,并且想知道一个好的模型的值范围是多少。任何帮助表示赞赏。谢谢。
我正在尝试使用 NLP 计算句子中单词的概率或任何类型的分数。我已经使用 Huggingface Transformers 库对 GPT2 模型尝试了这种方法,但是,由于模型的单向性质,我无法在上下文中进行预测,因此无法获得令人满意的结果。所以我想知道是否有办法使用 BERT 计算上述内容,因为它是双向的。
我发现这篇文章相关,我前几天随机看到的,但没有看到任何对我有用的答案。
希望我能够收到想法或解决方案。任何帮助表示赞赏。谢谢你。